Files
Platform-ts/src/lang/Disposable.ts

25 lines
466 B
TypeScript

import type IDisposable from './IDisposable';
export default class Disposable implements IDisposable {
private readonly _cleanup: () => void;
private _isDisposed: boolean;
constructor(cleanup: () => void) {
this._cleanup = cleanup;
this._isDisposed = false;
}
get isDisposed() {
return this._isDisposed;
}
public dispose(): void {
if (this._isDisposed) {
return;
}
this._cleanup();
this._isDisposed = true;
}
}