Follow Apple's doc, add NSOperation only after all configuration done.

This commit is contained in:
DreamPiggy 2018-02-28 01:09:26 +08:00
parent 71caeb82e4
commit 776ce2b85e
1 changed files with 4 additions and 2 deletions

View File

@ -235,7 +235,6 @@
operation.queuePriority = NSOperationQueuePriorityLow;
}
[sself.downloadQueue addOperation:operation];
if (sself.executionOrder == SDWebImageDownloaderLIFOExecutionOrder) {
// Emulate LIFO execution order by systematically adding new operations as last operation's dependency
[sself.lastAddedOperation addDependency:operation];
@ -289,6 +288,9 @@
UNLOCK(sself.operationsLock);
};
[self.URLOperations setObject:operation forKey:url];
// Add operation to operation queue only after all configuration done according to Apple's doc.
// `addOperation:` does not synchronously execute the `operation.completionBlock` so this will not cause deadlock.
[self.downloadQueue addOperation:operation];
}
UNLOCK(self.operationsLock);