Created
January 29, 2019 18:59
-
-
Save dgyesbreghs/7ca93d132646483fcec6f1d9456121ff to your computer and use it in GitHub Desktop.
Thread Safety with DispatchQueue
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
// | |
// DispatchQueu+ThreadSafety.swift | |
// BoleroPhone | |
// | |
// Created by Dylan Gyesbreghs on 29/01/2019. | |
// Copyright © 2019 iCapps. All rights reserved. | |
// | |
import Foundation | |
extension DispatchQueue { | |
class func sync(_ completion: () -> Void) { | |
if Thread.isMainThread { | |
completion() | |
} else { | |
main.sync(execute: completion) | |
} | |
} | |
class func async(_ completion: @escaping () -> Void) { | |
main.async(execute: completion) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment