storj/private/sync2/sleep.go

23 lines
371 B
Go
Raw Normal View History

2019-01-07 19:00:40 +00:00
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information
package sync2
import (
"context"
"time"
)
// Sleep implements sleeping with cancellation
func Sleep(ctx context.Context, duration time.Duration) bool {
timer := time.NewTimer(duration)
defer timer.Stop()
select {
case <-ctx.Done():
return false
case <-timer.C:
return true
}
}