Created
October 15, 2015 13:29
-
-
Save msonnabaum/62442dc2fc4f8caf402e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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