...

Source file src/github.com/shirou/gopsutil/internal/common/sleep.go

Documentation: github.com/shirou/gopsutil/internal/common

     1  package common
     2  
     3  import (
     4  	"context"
     5  	"time"
     6  )
     7  
     8  // Sleep awaits for provided interval.
     9  // Can be interrupted by context cancelation.
    10  func Sleep(ctx context.Context, interval time.Duration) error {
    11  	var timer = time.NewTimer(interval)
    12  	select {
    13  	case <-ctx.Done():
    14  		return ctx.Err()
    15  	case <-timer.C:
    16  		return nil
    17  	}
    18  }
    19  

View as plain text