Created
December 21, 2015 14:19
-
-
Save flier/749b82879b48dbc739eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
./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