-
Notifications
You must be signed in to change notification settings - Fork 226
Adds MultiCancellationToken
#2885
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
Changes from 8 commits
e8f68c1
3ba1712
04dfc4e
0fa3cf5
625b3a5
ccbe4ee
3699f0b
801df7b
76ec9e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { CancellationToken, Disposable } from "vscode"; | ||
| import { BasicDisposableObject } from "../disposable-object"; | ||
|
|
||
| /** | ||
| * A cancellation token that cancels when any of its constituent | ||
| * cancellation tokens are cancelled. | ||
| */ | ||
| export class MultiCancellationToken implements CancellationToken { | ||
| private readonly tokens: CancellationToken[]; | ||
|
|
||
| constructor(...tokens: CancellationToken[]) { | ||
| this.tokens = tokens; | ||
| } | ||
|
|
||
| get isCancellationRequested(): boolean { | ||
| return this.tokens.some((t) => t.isCancellationRequested); | ||
| } | ||
|
|
||
| onCancellationRequested<T>(listener: (e: T) => any): Disposable { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure we're implementing As I understand it, the purpose of This requires changes to a few different areas of the class so I can't really do this as a "suggestion" block, but I think the code would look like: export class MultiCancellationToken implements CancellationToken {
private readonly tokens: CancellationToken[];
private readonly onCancellationRequestedEvent = new EventEmitter<void>();
constructor(...tokens: CancellationToken[]) {
this.tokens = tokens;
tokens.forEach((t) =>
t.onCancellationRequested(() => this.onCancellationRequestedEvent.fire()),
);
}
get isCancellationRequested(): boolean {
return this.tokens.some((t) => t.isCancellationRequested);
}
get onCancellationRequested(): Event<any> {
return this.onCancellationRequestedEvent.event;
}
}What do you think?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. Good suggestion. Regarding cancellation by mouse hover, the way caching works, the first time the query runs to completion, all other query calls will use the cached results instead of calling it again. Sometimes the query completes quickly so it's hard to get the hover to cancel. Can you try this on a larger file in the archive?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is the behaviour I'm seeing, but unfortunately I still can't get it to cancel by breaking the hover. I picked a large file so the query took a few seconds to run. When it was running I could cancel the query by using the progress bar notification, but moving the mouse around seemingly did nothing. Once it had run to completion once it didn't run again and used cached results. I tried adding in some logging to As I said above, the code looks fine to me, so if we can't understand it and it works on your machine I'm happy to believe it and merge the code.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will verify this again locally. I'll also try to get a second screen recording. |
||
| const disposables = this.tokens.map((t) => | ||
| t.onCancellationRequested(listener), | ||
| ); | ||
| return new BasicDisposableObject(...disposables); | ||
| } | ||
| } | ||
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.
(Feel free to do now, ignore, or leave for a followup PR)
Could this just be the constructor of
DisposableObject, and avoid adding a new class? The case of passing no args is still allowed and would be a no-op, so it seems like it would be backwards compatible with existing uses ofDisposableObject.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.
DisposableObjectis currently abstract, so I'd need to change that, too. But maybe that's not a terrible thing.