Skip to content

Instantly share code, notes, and snippets.

@llinardos
Last active August 19, 2019 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save llinardos/1b8b6f5a918a3dba997695e9de6510fc to your computer and use it in GitHub Desktop.
Save llinardos/1b8b6f5a918a3dba997695e9de6510fc to your computer and use it in GitHub Desktop.
func onMainDo<T>(_ firstMainBlock: @escaping () -> Void, onBackgroundDo backgroundBlock: @escaping () -> T, thenOnMainDo mainBlock: @escaping (T) -> Void) {
DispatchQueue.main.async {
firstMainBlock()
DispatchQueue.global(qos: .background).async {
let result = backgroundBlock()
DispatchQueue.main.async {
mainBlock(result)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment