Last active
November 11, 2019 12:03
-
-
Save bdsaglam/c6aef56539b0a0e748fda83d59cd3bf7 to your computer and use it in GitHub Desktop.
Make an asynchronous function blocking
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
func callBlocking<T>( | |
_ closure: @escaping (_ continuationHandler: @escaping (T) -> Void ) -> Void ) | |
-> T { | |
let dispatchGroup = DispatchGroup() | |
dispatchGroup.enter() | |
var result:T? = nil | |
closure { res in | |
result = res | |
dispatchGroup.leave() | |
} | |
dispatchGroup.wait() | |
return result! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment