diff --git a/package.json b/package.json index 8a2381a..4e7bffa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hibas123/utils", - "version": "2.2.5", + "version": "2.2.6", "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 448434a..90aff1a 100644 --- a/src/awaiter.ts +++ b/src/awaiter.ts @@ -1,5 +1,7 @@ import Observable, { ObserverCallback } from "./observable"; +export type CheckFunction = (val: T) => boolean; + export default class AwaitStore { private observable = new Observable(); constructor(private _value: T) { @@ -49,7 +51,7 @@ export default class AwaitStore { * @param val Value to await */ awaitValue( - val: T + val: T | CheckFunction ): PromiseLike & { catch: (cb: (err: any) => PromiseLike) => PromiseLike; ignore: () => void; @@ -58,7 +60,12 @@ export default class AwaitStore { let prms = new Promise((yes) => { const cb = () => { - if (this._value === val) { + if (typeof val === "function") { + if ((val as CheckFunction)(this._value)) { + yes(); + this.unsubscribe(cb); + } + } else if (this._value === val) { yes(); this.unsubscribe(cb); }