UNPKG

1.12 kBTypeScriptView Raw
1import { AnyActorRef, SnapshotFrom } from "./types.js";
2interface WaitForOptions {
3 /**
4 * How long to wait before rejecting, if no emitted
5 * state satisfies the predicate.
6 *
7 * @defaultValue Infinity
8 */
9 timeout: number;
10}
11/**
12 * Subscribes to an actor ref and waits for its emitted value to satisfy
13 * a predicate, and then resolves with that value.
14 * Will throw if the desired state is not reached after an optional timeout.
15 * (defaults to Infinity).
16 *
17 * @example
18 * ```js
19 * const state = await waitFor(someService, state => {
20 * return state.hasTag('loaded');
21 * });
22 *
23 * state.hasTag('loaded'); // true
24 * ```
25 *
26 * @param actorRef The actor ref to subscribe to
27 * @param predicate Determines if a value matches the condition to wait for
28 * @param options
29 * @returns A promise that eventually resolves to the emitted value
30 * that matches the condition
31 */
32export declare function waitFor<TActorRef extends AnyActorRef>(actorRef: TActorRef, predicate: (emitted: SnapshotFrom<TActorRef>) => boolean, options?: Partial<WaitForOptions>): Promise<SnapshotFrom<TActorRef>>;
33export {};