SmartDispatchQueue

public class SmartDispatchQueue : Equatable

A dispatch queue that will call a sync block inline if it can tell we are already on that queue, avoiding the problem of having to know if you are on that queue already before calling sync().

It also supports synchronous execution of the block if on the correct queue already, or flipping that to async if we are not on this queue.

Note

This is not safe to use when using Dispatch Queues that use a target queue. The block will execute on the target queue, and getSpecific will not return the correct value
  • Undocumented

    Declaration

    Swift

    public let queue: DispatchQueue
  • Initialise with the given queue, with the ability to test if we are on this queue later.

    Declaration

    Swift

    public init(queue: DispatchQueue)
    • return: true if called on the same queue as this smart queue was initialised

    Declaration

    Swift

    public var isCurrentQueue: Bool { get }
  • Perform a block synchronously, without crashing if called on the same queue as this smart queue

    Declaration

    Swift

    @discardableResult
    public func sync<T>(execute block: () -> T) -> T
  • Perform a block synchronously, without crashing if called on the same queue as this smart queue, or fall back to asynchronous invocation on this queue.

    Declaration

    Swift

    public func syncOrAsyncIfDifferentQueue(execute block: @escaping () -> Void)
  • Declaration

    Swift

    public static func == (lhs: SmartDispatchQueue, rhs: SmartDispatchQueue) -> Bool