-
-
Save LutherBaker/16218c30756591a8c30083832e2d164e to your computer and use it in GitHub Desktop.
wait for condition to be true
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
import Foundation | |
func waitUntil(_ checkSuccess: @autoclosure ()->Bool) { | |
return waitUntil(1.0, checkSuccess) | |
} | |
func waitUntil(_ timeout: Double, _ checkSuccess: @autoclosure ()->Bool) { | |
let startDate = NSDate() | |
var success = false | |
while !success && abs(startDate.timeIntervalSinceNow) < timeout { | |
RunLoop.current.run(until: Date(timeIntervalSinceNow: 0.01)) | |
success = checkSuccess() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment