2
0
mirror of https://github.com/hibiken/asynq.git synced 2025-07-07 13:53:41 +08:00
2024-05-06 20:15:41 +08:00

20 lines
302 B
Go

package timeutil
import (
"context"
"time"
)
// Sleep will wait for the specified duration or return on context
// expiration.
func Sleep(ctx context.Context, d time.Duration) error {
t := time.NewTimer(d)
select {
case <-ctx.Done():
t.Stop()
return ctx.Err()
case <-t.C:
return nil
}
}