-
Notifications
You must be signed in to change notification settings - Fork 576
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
Implement BFTask Cancellation #71
Conversation
@interface BFTaskCancellationToken () | ||
|
||
@property (atomic, assign, readwrite, getter=isCancelled) BOOL cancelled; | ||
@property (nonatomic, retain) NSObject *lock; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I was curious about and would love some help understanding for my own education is why BFTask
creates a separate NSObject to use in its @synchronized
blocks (the pattern I cargo-culted here). Is there a particular reason for doing this over just using self
(as in @synchronized(self)
) which seems like it would be less risky since its less likely to errantly be modified or released?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Synchronizing around a private lock object is generally preferable to @synchronized(self)
blocks unless you specifically want to share the lock with other objects which is what happens with self, since other objects can call @synchronized(you)
.
The CancellationToken would better split into two classes like the C# API - CancellationToken and CancellationTokenSource. |
All Whereas in the C# threading API I believe you're referring to [1] This is a very different design, and while interesting I struggle to see how it is relevant. Though I'd be happy to be shown where I'm incorrect, perhaps you can point out what part of the 1 - Disclaimer: I am not a C# developer, but just looking at this doc |
@danielrhammond Apologies for not being very clear, I've listed the differences I think are worthwhile below. Separation of CancellationToken and CancellationTokenSource One difference is the separation of the
The code inside the method should not have access to the All the logic can still stay on the CancellationToken Listeners Another is the use of listeners (the
where
|
@danielrhammond Ideally the multiple |
While I agree @soleares its not very good looking cocoa (hence me calling it out in the initial description), that seems to be a change outside of the scope of this pull-request and should be considered carefully as a separate change especially given that it would break the public API. |
Cancellation is provided by a token passed into the continuation methods, which check for the cancelled state before executing their blocks and return a cancelled BFTask if necessary.
Just pushed up a rebase to fix the broken github auto-merge in case that helps provide some impetus for one of the maintainers to take a look. 🍻 |
This got superseeded by #89 |
@danielrhammond updated the pull request. |
Cancellation is provided by a token passed into the continuation methods, which check for the cancelled state before executing their blocks and return a cancelled BFTask if necessary, based on discussion from #18
Don't particularly like the multiple
with
s in the method signatures, but it seemed better to go follow the pattern ofcontinueWithExecutor:withBlock
/etc... really open to suggestions if you have something else you guys would prefer.