mirror of
https://github.com/mjl-/mox.git
synced 2025-07-10 07:14:40 +03:00
mox!
This commit is contained in:
19
mox-/sleep.go
Normal file
19
mox-/sleep.go
Normal file
@ -0,0 +1,19 @@
|
||||
package mox
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Sleep for d, but return as soon as ctx is done.
|
||||
//
|
||||
// Used for a few places where sleep is used to push back on clients, but where
|
||||
// shutting down should abort the sleep.
|
||||
func Sleep(ctx context.Context, d time.Duration) {
|
||||
t := time.NewTicker(d)
|
||||
defer t.Stop()
|
||||
select {
|
||||
case <-t.C:
|
||||
case <-ctx.Done():
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user