diff --git a/package.json b/package.json index e9105ed..115ff29 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hibas123/utils", - "version": "2.2.0", + "version": "2.2.1", "description": "Different Utilities, that are not worth own packages", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/awaiter.ts b/src/awaiter.ts index 5fea96e..150f413 100644 --- a/src/awaiter.ts +++ b/src/awaiter.ts @@ -28,7 +28,7 @@ export default class AwaitStore { awaitValue(val: T): PromiseLike & { catch: (cb: (err: any) => PromiseLike) => PromiseLike, ignore: () => void } { - let ignore: () => void; + let ignore: () => void = () => undefined; let prms = new Promise(yes => { const cb = () => { @@ -41,12 +41,15 @@ export default class AwaitStore { return false } - ignore = () => { - this.observable.unsubscribe(cb); - } - - if (!cb()) { - this.observable.subscribe(cb); + if (this._value === val) { + yes(); + } else { + ignore = () => { + this.observable.unsubscribe(cb); + } + if (!cb()) { + this.observable.subscribe(cb); + } } });