Last active
October 29, 2020 14:43
-
-
Save josephspurrier/ec57821bc4a3442a74ca to your computer and use it in GitHub Desktop.
Ticker on the Minute
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" | |
"time" | |
) | |
func main() { | |
log.Println("Started ticker") | |
// Tick on the minute | |
t := minuteTicker() | |
for { | |
// Wait for ticker to send | |
<-t.C | |
// Update the ticker | |
t = minuteTicker() | |
log.Println("Tick") | |
} | |
} | |
func minuteTicker() *time.Ticker { | |
// Return new ticker that triggers on the minute | |
return time.NewTicker(time.Second * time.Duration(60-time.Now().Second())) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment