htlcswitch/test: add waitForPaymentResult helper function
This commit is contained in:
parent
afd2d69906
commit
e7907e0e7c
@ -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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user