Skip to content

Commit 0fa3cf5

Browse files
committed
Use EventEmitter in MultiCancellationToken
1 parent 04dfc4e commit 0fa3cf5

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
1-
import { CancellationToken, Disposable } from "vscode";
1+
import { CancellationToken, Event, EventEmitter } from "vscode";
22

33
/**
44
* A cancellation token that cancels when any of its constituent
55
* cancellation tokens are cancelled.
66
*/
77
export class MultiCancellationToken implements CancellationToken {
88
private readonly tokens: CancellationToken[];
9+
private readonly onCancellationRequestedEvent = new EventEmitter<void>();
910

1011
constructor(...tokens: CancellationToken[]) {
1112
this.tokens = tokens;
13+
tokens.forEach((t) =>
14+
t.onCancellationRequested(() => this.onCancellationRequestedEvent.fire()),
15+
);
1216
}
1317

1418
get isCancellationRequested(): boolean {
1519
return this.tokens.some((t) => t.isCancellationRequested);
1620
}
1721

18-
onCancellationRequested<T>(listener: (e: T) => any): Disposable {
19-
this.tokens.forEach((t) => t.onCancellationRequested(listener));
20-
return {
21-
dispose: () => {
22-
this.tokens.forEach((t) =>
23-
t.onCancellationRequested(listener).dispose(),
24-
);
25-
},
26-
};
22+
get onCancellationRequested(): Event<any> {
23+
return this.onCancellationRequestedEvent.event;
2724
}
2825
}

0 commit comments

Comments
 (0)