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

Add cancelAllOperations to PINOperationQueue #122

Merged
merged 2 commits into from
Oct 11, 2016
Merged

Add cancelAllOperations to PINOperationQueue #122

merged 2 commits into from
Oct 11, 2016

Conversation

maicki
Copy link
Collaborator

@maicki maicki commented Oct 8, 2016

Add support to cancel all operations. Furthermore created a new method for cancelling an operation that the lock needs to be hold. This used by cancelOperation as well as cancelAllOperations now.

Copy link
Collaborator

@garrettmoon garrettmoon left a comment

Choose a reason for hiding this comment

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

Looks good, thank you!

- (void)cancelAllOperations
{
[self lock];
for (PINOperation *operation in [_referenceToOperations objectEnumerator]) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Another advantage of the _referenceToOperations weakTable :) We wouldn't have been able to enumerate over _queuedOperations without making a copy. Do you know if we need a copy here? Is it safe to enumerate over it even as objects are potentially being nil'd out by locked_cancelOperation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Seems like it's not safe to modify a mutable collection while enumerating through it via an NSEnumerator. So we probably have to make a copy.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like the right call to me.

@@ -128,18 +128,33 @@ - (void)dealloc
return reference;
}

- (void)cancelAllOperations
{
[self lock];
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: can you indent the code within the 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.

Done

@maicki
Copy link
Collaborator Author

maicki commented Oct 11, 2016

@garrettmoon Addressed comments

@garrettmoon garrettmoon merged commit ef38a9c into pinterest:master Oct 11, 2016
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.

2 participants