UNPKG

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