Alternatives to dispatch_get_current_queue() for completion blocks in iOS 6?

The pattern of “run on whatever queue the caller was on” is appealing, but ultimately not a great idea. That queue could be a low priority queue, the main queue, or some other queue with odd properties.

My favorite approach to this is to say “the completion block runs on an implementation defined queue with these properties: x, y, z”, and let the block dispatch to a particular queue if the caller wants more control than that. A typical set of properties to specify would be something like “serial, non-reentrant, and async with respect to any other application-visible queue”.

** EDIT **

Catfish_Man put an example in the comments below, I’m just adding it to his answer.

- (void) aMethodWithCompletionBlock:(dispatch_block_t)completionHandler     
{ 
    dispatch_async(self.workQueue, ^{ 
        [self doSomeWork]; 
        dispatch_async(self.callbackQueue, completionHandler); 
    } 
}

Leave a Comment