mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2025-06-16 00:56:09 +00:00
have Conn use Cancellation instead of manually setting up timers
This commit is contained in:
@ -75,6 +75,8 @@ func CancellationChild(parent Cancellation) Cancellation {
|
||||
return child
|
||||
}
|
||||
|
||||
var CancellationTimeoutError = errors.New("timeout")
|
||||
|
||||
func CancellationWithTimeout(parent Cancellation, timeout time.Duration) Cancellation {
|
||||
child := CancellationChild(parent)
|
||||
go func() {
|
||||
@ -83,7 +85,7 @@ func CancellationWithTimeout(parent Cancellation, timeout time.Duration) Cancell
|
||||
select {
|
||||
case <-child.Finished():
|
||||
case <-timer.C:
|
||||
child.Cancel(errors.New("timeout"))
|
||||
child.Cancel(CancellationTimeoutError)
|
||||
}
|
||||
}()
|
||||
return child
|
||||
|
Reference in New Issue
Block a user