Skip to content

Instantly share code, notes, and snippets.

@konradzdunczyk
Created September 25, 2020 17:59
Show Gist options
  • Save konradzdunczyk/c427cbf4766aec66b94562612e4131d9 to your computer and use it in GitHub Desktop.
Save konradzdunczyk/c427cbf4766aec66b94562612e4131d9 to your computer and use it in GitHub Desktop.

Revisions

  1. konradzdunczyk revised this gist Sep 25, 2020. No changes.
  2. konradzdunczyk created this gist Sep 25, 2020.
    13 changes: 13 additions & 0 deletions DispatchQueue.safeSync
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    extension DispatchQueue {
    func safeSync(execute block: () -> Void) {
    if isCurrent {
    block()
    } else {
    self.sync(execute: block)
    }
    }

    private var isCurrent: Bool {
    return OperationQueue.current?.underlyingQueue == self
    }
    }