Refactoring a colleague's code, and I'm looking for the equivalent of dispatch_barrier_async
in swift 3. There are a lot of queues at play, and his design is to block only this queue, and only for this single operation.
// Swift 2.3
func subscribe(subscriber: DaoDelegate) {
dispatch_barrier_async(self.subscribers.q) { // NOTE: barrier, requires exclusive access for write
//...
}
}
// Swift 3
func subscribe(subscriber: DaoDelegate) {
(self.subscribers.q).async { // (Not equivalent, no barrier on the concurrent queue)
//...
}
}
Can I keep that same functionality in Swift 3 without refactoring all the queue types?
The
async()
method has aflags
parameter which accepts a.barrier
option: