Make DisposableObject a concrete class

This commit is contained in:
Andrew Eisenberg
2023-10-04 20:09:47 +00:00
parent 801df7b14a
commit 76ec9e2e50
2 changed files with 10 additions and 14 deletions

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}