Adding JSDoc comments to awaiter

This commit is contained in:
Fabian Stamm 2020-02-06 18:05:05 +01:00
parent 811b03fd1b
commit 2545f3a050

View File

@ -7,24 +7,47 @@ export default class AwaitStore<T = any> {
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<T>) {
handler(this._value);
return this.observable.subscribe(handler);
}
/**
* Unsubscribe from changes
* @param handler The handler to unsubscribe
*/
unsubscribe(handler: ObserverCallback<T>) {
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<void> & { catch: (cb: (err: any) => PromiseLike<void>) => PromiseLike<void>, ignore: () => void } {
let ignore: () => void = () => undefined;
@ -62,6 +85,9 @@ export default class AwaitStore<T = any> {
}
}
/**
* Close this store. All subscribers will be unsubscribed and any further operations will fail
*/
close() {
this.observable.close();
}