Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add extension to support tests #96

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

LisaKonysheva
Copy link

No description provided.

beherith-auto1 and others added 5 commits May 17, 2017 17:11
Problem was that “isReady” property change KVO event was generated on every “state” property change, but in most of cases state-change doesn’t mean isReady-change. After every isReady KVO event, isReady property is read by NSOperations runtime. Since state-change (and as a result isReady KVO event) may happen and happens in multiple threads, isReady-getter is called from multiple threads too. The problem happens when isReady is called from multiple threads around the same time: the first call return False, but the second one returns True. Since there are two threads, first call can be actually finished after second one. In this case NSOperations runtime receivce isReady state value in the order like [false, false… false, true, false]. In this situation operations is actually ready, but it is not executed by queue (looks like because last isReady state was False).

To fix the described problem idea is to stop bombing with KVO events. Actually during NSOperation life isReady is changed only once from false -> true. So ideally is to have only one KVO event when operations is really ready.
@@ -96,7 +98,9 @@ open class OperationQueue: Foundation.OperationQueue {
*/
operation.addCompletionBlock { [weak self, weak operation] in
guard let queue = self, let operation = operation else { return }
queue.delegate?.operationQueue?(queue, operationDidFinish: operation, withErrors: [])
if let delegate = queue.delegate {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why write something more verbose? Optional chaining already indicated that we are only performing the delegate if the delegate exists.

@jjatie
Copy link

jjatie commented Nov 14, 2018

No description?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants