mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-26 20:30:10 +01:00
7d7fbf890e
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/203 Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/38
25 lines
500 B
Go
25 lines
500 B
Go
package aws
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// SleepWithContext will wait for the timer duration to expire, or the context
|
|
// is canceled. Which ever happens first. If the context is canceled the Context's
|
|
// error will be returned.
|
|
//
|
|
// Expects Context to always return a non-nil error if the Done channel is closed.
|
|
func SleepWithContext(ctx Context, dur time.Duration) error {
|
|
t := time.NewTimer(dur)
|
|
defer t.Stop()
|
|
|
|
select {
|
|
case <-t.C:
|
|
break
|
|
case <-ctx.Done():
|
|
return ctx.Err()
|
|
}
|
|
|
|
return nil
|
|
}
|