Skip to content

Instantly share code, notes, and snippets.

@mordvinov
Forked from josephspurrier/ticker.go
Created June 12, 2017 19:06
Show Gist options
  • Select an option

  • Save mordvinov/78ffb3dc5f63eda385790333f5808076 to your computer and use it in GitHub Desktop.

Select an option

Save mordvinov/78ffb3dc5f63eda385790333f5808076 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