github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/blog/content/race-detector/timer.go (about)

     1  // +build OMIT
     2  
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  	"math/rand"
     8  	"time"
     9  )
    10  
    11  func main() {
    12  	start := time.Now()
    13  	var t *time.Timer
    14  	t = time.AfterFunc(randomDuration(), func() {
    15  		fmt.Println(time.Now().Sub(start))
    16  		t.Reset(randomDuration())
    17  	})
    18  	time.Sleep(5 * time.Second)
    19  }
    20  
    21  func randomDuration() time.Duration {
    22  	return time.Duration(rand.Int63n(1e9))
    23  }