htlcswitch/test: add waitForPaymentResult helper function

This commit is contained in:
Joost Jager committed 2019-02-06 07:29:24 +01:00
1 parent afd2d69906
commit e7907e0e7c
1 file changed
+10 -4
+10 -4
View File
@@ -657,12 +657,18 @@ type paymentResponse struct {
} }
func (r *paymentResponse) Wait(d time.Duration) (lntypes.Hash, error) { 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 { select {
case err := <-r.err: case err := <-c:
close(r.err) close(c)
return r.rhash, err return err
case <-time.After(d): case <-time.After(d):
return r.rhash, errors.New("htlc was not settled in time") return errors.New("htlc was not settled in time")
} }
} }