Skip to content

waitFor

Callable

  • waitFor<TActorRef>(actorRef: TActorRef, predicate: (emitted: SnapshotFrom<TActorRef>) => boolean, options?: Partial<WaitForOptions>): Promise<SnapshotFrom<TActorRef>>

  • Subscribes to an actor ref and waits for its emitted value to satisfy a predicate, and then resolves with that value. Will throw if the desired state is not reached after a timeout (defaults to 10 seconds).

    @example
    const state = await waitFor(someService, state => {
    return state.hasTag('loaded');
    });

    state.hasTag('loaded'); // true

    Type parameters

    Parameters

    • actorRef: TActorRef

      The actor ref to subscribe to

    • predicate: (emitted: SnapshotFrom<TActorRef>) => boolean

      Determines if a value matches the condition to wait for

    • optionaloptions: Partial<WaitForOptions>

    Returns Promise<SnapshotFrom<TActorRef>>

    A promise that eventually resolves to the emitted value that matches the condition