mirror of https://github.com/shirou/gopsutil
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
317 B
Go
19 lines
317 B
Go
5 years ago
|
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
|
||
|
}
|
||
|
}
|