parallel-universe
Version:
The set of async flow control structures and promise utils.
23 lines (22 loc) • 777 B
TypeScript
/**
* Provides mechanism for blocking async processes and unblocking them from an external context.
*
* @template T The value that can be passed to {@link unblock} to resolve the {@link block} promise.
*/
export declare class Blocker<T = void> {
private _promise?;
private _unblock?;
/**
* `true` if {@link Blocker} is blocked and wasn't unblocked yet, or `false` otherwise.
*/
get isBlocked(): boolean;
/**
* Returns promises that is fulfilled with the result passed to {@link unblock}. If blocker is already blocked
* then the same promise is returned.
*/
block(): Promise<T>;
/**
* Fulfills the promise returned from {@link block}. If the blocker isn't blocked then no-op.
*/
unblock(value: T): void;
}