http-server-status/vendor/github.com/shirou/gopsutil/internal/common/sleep.go

19 lines
317 B
Go
Raw Normal View History

2021-09-20 09:28:00 +00:00
package common
import (
"context"
"time"
)
// Sleep awaits for provided interval.
// Can be interrupted by context cancelation.
func Sleep(ctx context.Context, interval time.Duration) error {
var timer = time.NewTimer(interval)
select {
case <-ctx.Done():
return ctx.Err()
case <-timer.C:
return nil
}
}