TealiumQueue Class Reference
public class TealiumQueue
A wrapper class around DispatchQueue to only dispatch asynchronously when we are on a different queue.
Making it dispatch synchronously in a generic library would instead be not safe and could lead to deadlocks. An example of deadlock that would look safe is this:
DispatchQueue.main.async {
let queue = TealiumQueue(label: "something")
queue.ensureOnQueue {
print("This will print")
DispatchQueue.main.sync { // This is something that a user might do on one of our completions
print("This will never print")
}
}
queue.syncOnQueue { // This is something that might be part of our library if we do introduce a method like this
print("This will never print")
}
}
Therefore we only have, and only should have, an async method which is ensureOnQueue.
-
The main queue for UI-related operations.
Declaration
Swift
public static let main: TealiumQueue -
A background worker queue for SDK operations.
Declaration
Swift
public static let worker: TealiumQueue -
The underlying dispatch queue.
Declaration
Swift
public let dispatchQueue: DispatchQueue -
Creates a new queue with the specified label and quality of service.
Declaration
Swift
public convenience init(label: String, qos: DispatchQoS = .default)Parameter Description labelThe label for the queue.
qosThe quality of service level.
-
Ensures that the work will be executed on the queue. If we are currently running on that queue the code will be synchronous, otherwise it will be asynchronous.
Can skip dispatch only if we don’t want to specify any other parameters for the dispatch. If we do than we need to call directly the queue.async method as we don’t just want to make sure it’s the correct queue. This method can, and will, be asynchronous if we are on a different queue.
Declaration
Swift
public func ensureOnQueue(_ work: @escaping () -> Void) -
Returns true if the currently running code is on the queue embedded in this class.
Declaration
Swift
public func isOnQueue() -> Bool