Added reset to resolvable.ts

This commit is contained in:
Sebastian Seedorf
2020-11-19 22:21:59 +01:00
parent 3a58260d12
commit 055d11b9b1

View File

@@ -13,8 +13,13 @@ class FetchOnce<T, U extends Array<unknown>> {
constructor(protected fetchMethod?: (...args: U) => Promise<T>) { }
public reset(): void {
this.data = undefined;
this.error = undefined;
this.state = ResolvableState.WAITING;
}
public resolve(...args: U): Promise<T> {
// eslint-disable-next-line promise/avoid-new
return new Promise((resolve, reject) => {
switch (this.state) {
case ResolvableState.WAITING:
@@ -76,4 +81,9 @@ export class WaitForSync<T> extends FetchOnce<T, never> {
this.parsePromise((async () => { throw error; })());
}
}
public reset(): void {
super.reset();
this.state = ResolvableState.PENDING;
}
}