Skip to content

Commit

Permalink
feat: add safe async
Browse files Browse the repository at this point in the history
  • Loading branch information
gtokman committed May 8, 2021
1 parent b98bdce commit 8544301
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions 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)
}
}
}

0 comments on commit 8544301

Please sign in to comment.