I've run into an issue I had never seen before. I never thought it might exist. I'm using DFCache
library and in a certain moment dispatch_async
using global queue doesn't execute block.
- (void)cachedObjectForKey:(NSString *)key completion:(void (^)(id))completion {
if (!key.length) {
_dwarf_cache_callback(completion, nil);
return;
}
id object = [self.memoryCache objectForKey:key];
if (object != nil) {
_dwarf_cache_callback(completion, object);
return;
}
NSLog(@"Before calling async %d queue %p", [NSThread isMainThread], _processingQueue);
dispatch_async(_processingQueue, ^{
NSLog(@"Block called");
@autoreleasepool {
id object = [self _cachedObjectForKey:key];
_dwarf_cache_callback(completion, object);
}
});
}
this is how this queue was created:
_processingQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
the queue is never used in any other place. This is not my code. This is the code of DFCache
library. But there's something in my code affecting the queue because it stops working always in a particular moment. I load, save, load, save, load and ... the block is not called. But I can't understand why. I need to know what may cause the block to be not called on dispatch_async
. My code is so big and complex so I don't post it here. What I need is a hint. What specific reason might cause this behaviour? Did you ever see dispatch_async
not calling its block on a global queue? What was causing that?