-
Notifications
You must be signed in to change notification settings - Fork 1
Queue
Queue
s manage the execution of closures you give to them.
Serial queues execute their closures one at a time.
Concurrent queues execute their closures many at a time (depending on system conditions).
All queues always execute their closures in order. Serial queues' closures always finish in order. Concurrent queues' closures do not always finish in order.
myQueue.isConcurrent
is useful for knowing what kind of queue you're working with.
Queue
runs on top of the traditional dispatch queue.
gcd
: The Dispatcher
singleton. The concurrent queue for default-priority tasks.
gcd.main
: The serial queue for the user interface. Learn more about the main queue.
gcd.high
: The concurrent queue for high-priority tasks.
gcd.low
: The concurrent queue for low-priority tasks.
gcd.background
: The concurrent queue for zero-priority tasks.
gcd.main.async {
let currentQueue: Queue = gcd.current // gcd.main
let queueIsCurrent: Bool = currentQueue.isCurrent // true
}
current
is only available on gcd
.
isCurrent
is available on all Queue
s.
You must retain self-made queues!
let serialQueue = gcd.serial()
let concurrentQueue = gcd.concurrent()
Queue
s prevent deadlocks on the current queue. The example below would deadlock the main queue if you weren't using this framework!
gcd.main.sync {
gcd.main.sync { // normally deadlocks
println("hello world")
}
}
Instead, the Queue
just pretends like you did this:
gcd.main.sync {
println("hello world")
}