You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.
// sleepContext sleeps for the specified duration or until ctx ends, and reports// whether the sleep ended due to context cancellation.funcsleepContext(ctx context.Context, dur time.Duration) bool {
select {
case<-time.After(dur):
returnfalsecase<-ctx.Done():
returntrue
}
}
Note that after the context ends the timer will run to completion before it will be GC'd. If that matters you can do something more explicit with time.NewTimer. But in general that is probably safe unless you start a lot of these and they run for a long time.
Your solution is better since the fact that the After is of course interrupted if the ctx is Done went over me so I was dumbly doing smaller sleeps, I'm updating the PR, thanks!
we are just calling to time.Sleep, and that cannot be canceled from the Context. Change sleep to make it cancellable.
The text was updated successfully, but these errors were encountered: