Make DisposableObject a concrete class
This commit is contained in:
@@ -9,10 +9,16 @@ export type DisposeHandler = (disposable: Disposable) => void;
|
||||
/**
|
||||
* Base class to make it easier to implement a `Disposable` that owns other disposable object.
|
||||
*/
|
||||
export abstract class DisposableObject implements Disposable {
|
||||
export class DisposableObject implements Disposable {
|
||||
private disposables: Disposable[] = [];
|
||||
private tracked?: Set<Disposable> = undefined;
|
||||
|
||||
constructor(...dispoables: Disposable[]) {
|
||||
for (const d of dispoables) {
|
||||
this.push(d);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds `obj` to a list of objects to dispose when `this` is disposed. Objects added by `push` are
|
||||
* disposed in reverse order of being added.
|
||||
@@ -82,12 +88,3 @@ export abstract class DisposableObject implements Disposable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class BasicDisposableObject extends DisposableObject {
|
||||
constructor(...dispoables: Disposable[]) {
|
||||
super();
|
||||
for (const d of dispoables) {
|
||||
this.push(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { CancellationToken, Disposable } from "vscode";
|
||||
import { BasicDisposableObject } from "../disposable-object";
|
||||
import { DisposableObject } from "../disposable-object";
|
||||
|
||||
/**
|
||||
* A cancellation token that cancels when any of its constituent
|
||||
@@ -17,9 +17,8 @@ export class MultiCancellationToken implements CancellationToken {
|
||||
}
|
||||
|
||||
onCancellationRequested<T>(listener: (e: T) => any): Disposable {
|
||||
const disposables = this.tokens.map((t) =>
|
||||
t.onCancellationRequested(listener),
|
||||
return new DisposableObject(
|
||||
...this.tokens.map((t) => t.onCancellationRequested(listener)),
|
||||
);
|
||||
return new BasicDisposableObject(...disposables);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user