Skip to content

Instantly share code, notes, and snippets.

@raecoo
Last active September 28, 2019 13:28
Show Gist options
  • Save raecoo/c40463fdfa277a63c97aa02fd11a3af1 to your computer and use it in GitHub Desktop.
Save raecoo/c40463fdfa277a63c97aa02fd11a3af1 to your computer and use it in GitHub Desktop.
Repetitive background tasks
ticker := time.NewTicker(5 * time.Second)
quit := make(chan struct{})
go func() {
for {
select {
case <- ticker.C:
// do stuff
case <- quit:
ticker.Stop()
return
}
}
}()
go (func() {
for {
select {
case <- chan.type:
return
default:
}
time.Sleep(time.Duration(5) * time.Second)
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment