Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@josephspurrier
Last active October 29, 2020 14:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save josephspurrier/ec57821bc4a3442a74ca to your computer and use it in GitHub Desktop.
Save josephspurrier/ec57821bc4a3442a74ca to your computer and use it in GitHub Desktop.
Ticker on the Minute
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