depot/go/trains/darwin/util.go

18 lines
225 B
Go

package darwin
import (
"context"
"time"
)
func Sleep(ctx context.Context, d time.Duration) error {
t := time.NewTicker(d)
defer t.Stop()
select {
case <-t.C:
return nil
case <-ctx.Done():
return ctx.Err()
}
}