Skip to content

Instantly share code, notes, and snippets.

@bdsaglam
Last active November 11, 2019 12:03
Show Gist options
  • Save bdsaglam/c6aef56539b0a0e748fda83d59cd3bf7 to your computer and use it in GitHub Desktop.
Save bdsaglam/c6aef56539b0a0e748fda83d59cd3bf7 to your computer and use it in GitHub Desktop.
Make an asynchronous function blocking
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