Skip to content

Instantly share code, notes, and snippets.

@flier
Created December 21, 2015 14:19
Show Gist options
  • Save flier/749b82879b48dbc739eb to your computer and use it in GitHub Desktop.
Save flier/749b82879b48dbc739eb to your computer and use it in GitHub Desktop.
package main
import (
"log"
"sync"
"../.."
)
func main() {
scheduler := gocron.NewTimerWheel(nil)
var wg sync.WaitGroup
wg.Add(61)
secondCount := 1
scheduler.Every(1).Second().Do(func() {
log.Printf("%d second", secondCount)
secondCount++
wg.Done()
})
scheduler.Every(1).Minute().Do(func() {
log.Printf("%d minute", secondCount/60)
wg.Done()
})
scheduler.Every(1).Hour().Do(func() {
log.Printf("%d hour", secondCount/(60*60))
})
stopped := scheduler.Start()
wg.Wait()
stopped <- true
}
@flier
Copy link
Author

flier commented Dec 21, 2015

./gocron  2854  22:11:04
2015/12/21 22:11:07 1 second
2015/12/21 22:11:08 2 second
2015/12/21 22:11:09 3 second
2015/12/21 22:11:10 4 second
2015/12/21 22:11:11 5 second
...
2015/12/21 22:12:05 59 second
2015/12/21 22:12:06 1 minute
2015/12/21 22:12:06 60 second

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment