-
Notifications
You must be signed in to change notification settings - Fork 580
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 cancellation token package #2
Conversation
f24e0df
to
a2b6999
Compare
a2b6999
to
7f7ed81
Compare
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.
Generally looks good, but with the very large caveat that this is totally undocumented, so I'm not sure what problem this is trying to solve.
a5c1dc6
to
028ee7d
Compare
* Creates a new Token object linked to this TokenSource (i.e., one that | ||
* will signal cancellation when this source has been cancelled). | ||
*/ | ||
get token(): Token { |
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.
Why use a getter here instead of a method? It seems a little weird here because the following is not intuitive:
const tokenSource = new TokenSource();
// expect next line to be 'true' but instead get 'false'
tokenSource.token === tokenSource.token;
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.
Good point. I'll switch this to a method.
/** | ||
* Alias of this.cancellable | ||
*/ | ||
get canBeCancelled(): boolean { |
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.
Why do we need both Token.cancellable and Token.canBeCancelled fields if they return the same thing?
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.
I thought canBeCancelled
was more accurate but a bit verbose, but it's not necessary.
/** | ||
* Alias of this.canceled | ||
*/ | ||
get isCancellationRequested(): boolean { |
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.
Same comment about using aliased fields.
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.
Will remove.
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.
Approved assuming docs get added back for getToken!
@@ -12,27 +12,20 @@ export class Token { | |||
* Whether the associated operation may be cancelled at some point in the | |||
* future. | |||
*/ | |||
public readonly cancellable: boolean; | |||
public readonly canBeCancelled: boolean; |
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.
Optional: I actually liked cancellable
, but it doesn't really matter.
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.
Agreed.
@@ -50,6 +42,10 @@ export class TokenSource { | |||
} | |||
} | |||
|
|||
getToken(): Token { |
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.
Minor: The docs for token
should be moved here as well.
Add cancellation token package
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread. |
/cc @chrisradek