Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zazk/4cad8033e0f4c1337c3340059d69a506 to your computer and use it in GitHub Desktop.
Save zazk/4cad8033e0f4c1337c3340059d69a506 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