diff --git a/Sources/ExtensionKit/Foundation/DispactQueue.swift b/Sources/ExtensionKit/Foundation/DispactQueue.swift new file mode 100644 index 0000000..8a26116 --- /dev/null +++ b/Sources/ExtensionKit/Foundation/DispactQueue.swift @@ -0,0 +1,14 @@ +import Foundation + +extension DispatchQueue { + + /// Run closure if thread is main else switch to main and run the closure + /// - Parameter work: Closure to run + static func mainSafeAsync(execute work: @escaping () -> Void) { + if Thread.isMainThread { + work() + } else { + main.async(execute: work) + } + } +}