Forked from llinardos/MainBackgroundMainUtility.swift
Created
August 19, 2019 11:01
-
-
Save zazk/4cad8033e0f4c1337c3340059d69a506 to your computer and use it in GitHub Desktop.
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 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