Skip to content

Instantly share code, notes, and snippets.

@onevcat
Created March 8, 2017 02:42
Show Gist options
  • Save onevcat/f965be103570a5e6f44149e08e905a3c to your computer and use it in GitHub Desktop.
Save onevcat/f965be103570a5e6f44149e08e905a3c to your computer and use it in GitHub Desktop.
func waitUntil(_ done: @escaping (@escaping () -> Void) -> Void) {
var completed: UInt32 = 0
DispatchQueue.main.async {
done { OSAtomicOr32Barrier(1, &completed) }
}
while completed == 0 {
RunLoop.current.run(until: Date(timeIntervalSinceNow: 0.01))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment