mirror of
https://github.com/kopia/kopia.git
synced 2026-02-18 15:05:46 -05:00
19 lines
376 B
Go
19 lines
376 B
Go
package clock
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// SleepInterruptibly sleeps for the given amount of time, while also honoring cancellation signal.
|
|
// Returns false if canceled, true if slept for the entire duration.
|
|
func SleepInterruptibly(ctx context.Context, dur time.Duration) bool {
|
|
select {
|
|
case <-ctx.Done():
|
|
return false
|
|
|
|
case <-time.After(dur):
|
|
return true
|
|
}
|
|
}
|