diff --git a/src/awaiter.ts b/src/awaiter.ts index a86c02c..72ce391 100644 --- a/src/awaiter.ts +++ b/src/awaiter.ts @@ -7,24 +7,47 @@ export default class AwaitStore { this.unsubscribe = this.unsubscribe.bind(this); } + /** + * Get the current value + */ get value() { return this._value; } + /** + * Set a new value and notify subscribers + * @param value Value to be set + */ send(value: T) { this._value = value; this.observable.send(value); } + /** + * Get the current value as well as all changes + * @param handler Handler called on change + */ subscribe(handler: ObserverCallback) { handler(this._value); return this.observable.subscribe(handler); } + /** + * Unsubscribe from changes + * @param handler The handler to unsubscribe + */ unsubscribe(handler: ObserverCallback) { this.observable.unsubscribe(handler); } + /** + * Await a specific value and return. + * + * For example if val = true then this function would block until the value + * is actually true. If it is true, then the promise will resolve immediatly + * + * @param val Value to await + */ awaitValue(val: T): PromiseLike & { catch: (cb: (err: any) => PromiseLike) => PromiseLike, ignore: () => void } { let ignore: () => void = () => undefined; @@ -62,6 +85,9 @@ export default class AwaitStore { } } + /** + * Close this store. All subscribers will be unsubscribed and any further operations will fail + */ close() { this.observable.close(); }