Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Created December 22, 2020 17:57
Show Gist options
  • Save BetterProgramming/5e07ec1c84d589f54329147c5d233dfb to your computer and use it in GitHub Desktop.
Save BetterProgramming/5e07ec1c84d589f54329147c5d233dfb to your computer and use it in GitHub Desktop.
extension DispatchQueue {
static func background(delay: Double = 0.0, background: (()->Void)? = nil, completion: (() -> Void)? = nil) {
DispatchQueue.main.async {
background?()
if let completion = completion {
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: {
completion()
})
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment