Skip to content

Instantly share code, notes, and snippets.

@msonnabaum
Created October 15, 2015 13:29
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 msonnabaum/62442dc2fc4f8caf402e to your computer and use it in GitHub Desktop.
Save msonnabaum/62442dc2fc4f8caf402e to your computer and use it in GitHub Desktop.
func WaitUntil(f func() bool, seconds int) {
done := make(chan bool)
go func() {
time.Sleep(time.Duration(seconds) * time.Second)
done <- true
}()
go func() {
for {
if f() {
done <- true
}
}
}()
select {
case <-done:
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment