Skip to content

Instantly share code, notes, and snippets.

@dgyesbreghs
Created January 29, 2019 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgyesbreghs/7ca93d132646483fcec6f1d9456121ff to your computer and use it in GitHub Desktop.
Save dgyesbreghs/7ca93d132646483fcec6f1d9456121ff to your computer and use it in GitHub Desktop.
Thread Safety with DispatchQueue
//
// 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