Optimized how enqueueing operations works
- Removed the NSBlockOperation as it was not longer needed for completion block to be fired appropriately - Added a safety call to setCompletionBlock in AFHTTPRequestOperation to ensure that dispatch_group_leave would be called
This commit is contained in:
parent
e47fc50903
commit
8b94ef8e44
2 changed files with 8 additions and 13 deletions
|
|
@ -517,16 +517,6 @@ static void AFReachabilityCallback(SCNetworkReachabilityRef __unused target, SCN
|
||||||
{
|
{
|
||||||
dispatch_group_t dispatchGroup = dispatch_group_create();
|
dispatch_group_t dispatchGroup = dispatch_group_create();
|
||||||
|
|
||||||
NSBlockOperation *batchedOperation = [NSBlockOperation blockOperationWithBlock:^{
|
|
||||||
if (completionBlock) {
|
|
||||||
dispatch_group_notify(dispatchGroup, dispatch_get_main_queue(), ^{
|
|
||||||
completionBlock(operations);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
|
|
||||||
[self.operationQueue addOperation:batchedOperation];
|
|
||||||
|
|
||||||
NSPredicate *finishedOperationPredicate = [NSPredicate predicateWithFormat:@"isFinished == YES"];
|
NSPredicate *finishedOperationPredicate = [NSPredicate predicateWithFormat:@"isFinished == YES"];
|
||||||
|
|
||||||
for (AFHTTPRequestOperation *operation in operations) {
|
for (AFHTTPRequestOperation *operation in operations) {
|
||||||
|
|
@ -535,7 +525,7 @@ static void AFReachabilityCallback(SCNetworkReachabilityRef __unused target, SCN
|
||||||
operation.completionBlock = ^{
|
operation.completionBlock = ^{
|
||||||
if (progressBlock) {
|
if (progressBlock) {
|
||||||
dispatch_group_async(dispatchGroup, dispatch_get_main_queue(), ^{
|
dispatch_group_async(dispatchGroup, dispatch_get_main_queue(), ^{
|
||||||
progressBlock([[batchedOperation.dependencies filteredArrayUsingPredicate:finishedOperationPredicate] count], [batchedOperation.dependencies count]);
|
progressBlock([[operations filteredArrayUsingPredicate:finishedOperationPredicate] count], [operations count]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -543,11 +533,15 @@ static void AFReachabilityCallback(SCNetworkReachabilityRef __unused target, SCN
|
||||||
originalCompletionBlock();
|
originalCompletionBlock();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
[batchedOperation addDependency:operation];
|
|
||||||
[self enqueueHTTPRequestOperation:operation];
|
[self enqueueHTTPRequestOperation:operation];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (completionBlock) {
|
||||||
|
dispatch_group_notify(dispatchGroup, dispatch_get_main_queue(), ^{
|
||||||
|
completionBlock(operations);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
dispatch_release(dispatchGroup);
|
dispatch_release(dispatchGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) {
|
||||||
|
|
||||||
self.acceptableStatusCodes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 100)];
|
self.acceptableStatusCodes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 100)];
|
||||||
self.dispatchSemaphore = dispatch_semaphore_create(1);
|
self.dispatchSemaphore = dispatch_semaphore_create(1);
|
||||||
|
self.completionBlock = NULL;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue