mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
throw when something tracked is not disposable, fail early
This commit is contained in:
parent
1289f065d6
commit
3ab68ef438
@ -22,6 +22,10 @@ function disposeValue(value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isDisposable(value) {
|
||||||
|
return value && (typeof value === "function" || typeof value.dispose === "function");
|
||||||
|
}
|
||||||
|
|
||||||
export class Disposables {
|
export class Disposables {
|
||||||
constructor() {
|
constructor() {
|
||||||
this._disposables = [];
|
this._disposables = [];
|
||||||
@ -31,6 +35,9 @@ export class Disposables {
|
|||||||
if (this.isDisposed) {
|
if (this.isDisposed) {
|
||||||
throw new Error("Already disposed, check isDisposed after await if needed");
|
throw new Error("Already disposed, check isDisposed after await if needed");
|
||||||
}
|
}
|
||||||
|
if (!isDisposable(disposable)) {
|
||||||
|
throw new Error("Not a disposable");
|
||||||
|
}
|
||||||
this._disposables.push(disposable);
|
this._disposables.push(disposable);
|
||||||
return disposable;
|
return disposable;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user