dispatch_queue_t callerQueue = dispatch_get_current_queue();
dispatch_retain(callerQueue);
dispatch_queue_t downloadQueue = dispatch_queue_create("Download Queue",NULL);
dispatch_async(downloadQueue,
^{
//some code that accesses a web service
dispatch_async(callerQueue,
^{
//some code that accesses UI
});
});
dispatch_release(downloadQueue);
NSLog(@"great successing!");
The problem is that “Great successing!” never shows up, and nothing ever happens beyond the end of the code outermost dispatch_async block. I’m not sure what I’m doing wrong but I know there is something seriously wrong with this.
You are releasing your download queue too early. You need to wait until after it has executed the block. The
dispatch_asyncman page suggests putting the release at the end of the block.