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

[Operation] add willChangeValue() and didChangeValue() #836

Merged
merged 3 commits into from Mar 23, 2017

Conversation

ianpartridge
Copy link
Collaborator

Following on from the discussion on the swift-corelibs-dev mailing list, here's a PR to add willChangeValue() and didChangeValue() to Operation, in support of operations that are asynchronous from an operation queue.

@ianpartridge ianpartridge changed the title Operation: add willChangeValue() and didChangeValue() [Operation] add willChangeValue() and didChangeValue() Jan 24, 2017
@@ -47,7 +47,6 @@ open class Operation : NSObject {
#endif
}

/// - Note: Operations that are asynchronous from the execution of the operation queue itself are not supported since there is no KVO to trigger the finish.
open func start() {
Copy link
Member

Choose a reason for hiding this comment

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

So the problem now is that if someone overrides main but not start and detaches from the current operation's queue.

Copy link
Member

Choose a reason for hiding this comment

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

Can we document and live with that for now to unblock this particular use case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Any updates on this? The limitation @phausler identifies seems less serious than the current one.

Copy link
Member

Choose a reason for hiding this comment

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

it seems like the lesser of two evils. so seems like a decent work-around until we have a better answer

Copy link
Member

Choose a reason for hiding this comment

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

could you perhaps add a simple unit test to verify the expected behavior?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@phausler @parkera I've added a test for this. Please could you review and run CI?

@parkera
Copy link
Member

parkera commented Feb 17, 2017

@swift-ci please test

@alblue
Copy link
Contributor

alblue commented Feb 22, 2017

There is a test failure on this - can you investigate and fix if necessary?

Test Case 'TestNSOperationQueue.test_AsyncOperation' started at 15:38:06.845
TestFoundation/TestNSOperationQueue.swift:80: error: TestNSOperationQueue.test_AsyncOperation : XCTAssertTrue failed - 
TestFoundation/TestNSOperationQueue.swift:81: error: TestNSOperationQueue.test_AsyncOperation : XCTAssertFalse failed - 

@ianpartridge
Copy link
Collaborator Author

Will do. Race condition, I think.


private let queue = DispatchQueue(label: "async.operation.queue")

private var _executing = false
Copy link
Member

Choose a reason for hiding this comment

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

these two variables must be changed under the same lock

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you mean where they are updated at the end of the queue.async() block below?

What's the best way to do this? NSLock?

Copy link
Member

Choose a reason for hiding this comment

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

NSLock should work, yes.

@ianpartridge
Copy link
Collaborator Author

@parkera Updated based on feedback - thanks. Please test and merge if you are happy.

@parkera
Copy link
Member

parkera commented Mar 21, 2017

@swift-ci please test

@ianpartridge
Copy link
Collaborator Author

@parkera tests passed 😄

@parkera
Copy link
Member

parkera commented Mar 23, 2017

Thanks!

@parkera
Copy link
Member

parkera commented Mar 23, 2017

@swift-ci test and merge

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.

None yet

5 participants