Add Disposable and DisposableList
This commit is contained in:
24
src/lang/Disposable.ts
Normal file
24
src/lang/Disposable.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user