Skip to content

Instantly share code, notes, and snippets.

@prnvbn
Created August 13, 2021 08:33
Show Gist options
  • Save prnvbn/41df80afd416b5b19a846e06dd98b1ee to your computer and use it in GitHub Desktop.
Save prnvbn/41df80afd416b5b19a846e06dd98b1ee to your computer and use it in GitHub Desktop.
A task running periodically in the background in Golang.
ticker := time.NewTicker(70 * time.Second)
quit := make(chan struct{})
go func() {
for {
select {
case <-ticker.C:
// do the task here
case <-quit:
ticker.Stop()
return
}
}
}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment