Skip to content

Instantly share code, notes, and snippets.

@beautyfree
Last active September 21, 2017 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beautyfree/54bbd5e9289408b76e934f7e4b7d805b to your computer and use it in GitHub Desktop.
Save beautyfree/54bbd5e9289408b76e934f7e4b7d805b to your computer and use it in GitHub Desktop.
Repeatable periodical task job with timeout stop
func schedule(what func(), timeout time.Duration) {
ch := make(chan bool)
go func() {
what()
ch <- true
}()
select {
case <-time.After(timeout):
return
case <-ch:
return
}
}
func main() {
for {
schedule(taskPoloniex, 30 * time.Second)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment