1package mox
2
3import (
4 "context"
5 "time"
6)
7
8// Sleep for d, but return as soon as ctx is done.
9//
10// Used for a few places where sleep is used to push back on clients, but where
11// shutting down should abort the sleep.
12func Sleep(ctx context.Context, d time.Duration) {
13 t := time.NewTicker(d)
14 defer t.Stop()
15 select {
16 case <-t.C:
17 case <-ctx.Done():
18 }
19}
20