htlcswitch/test: add waitForPaymentResult helper function

This commit is contained in:
Joost Jager 2019-01-29 14:13:02 +01:00
parent afd2d69906
commit e7907e0e7c
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

@ -657,12 +657,18 @@ type paymentResponse struct {
}
func (r *paymentResponse) Wait(d time.Duration) (lntypes.Hash, error) {
return r.rhash, waitForPaymentResult(r.err, d)
}
// waitForPaymentResult waits for either an error to be received on c or a
// timeout.
func waitForPaymentResult(c chan error, d time.Duration) error {
select {
case err := <-r.err:
close(r.err)
return r.rhash, err
case err := <-c:
close(c)
return err
case <-time.After(d):
return r.rhash, errors.New("htlc was not settled in time")
return errors.New("htlc was not settled in time")
}
}