Created
August 13, 2021 08:33
-
-
Save prnvbn/41df80afd416b5b19a846e06dd98b1ee to your computer and use it in GitHub Desktop.
A task running periodically in the background in Golang.
This file contains 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
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