• Pauses the workflow until a signal with the given signalId is received. The workflow suspends durably — it survives process restarts and will resume exactly once when the matching signal() call delivers data.

    waitFor is the receive side of the signal coordination pair. The send side is signal(), which can be called from another workflow, a hook function, or externally via Durable.Client.workflow.signal().

    On replay, waitFor returns the previously stored signal payload immediately (no actual suspension occurs).

    import { Durable } from '@hotmeshio/hotmesh';

    // Human-in-the-loop approval pattern
    export async function approvalWorkflow(orderId: string): Promise<boolean> {
    const { submitForReview } = Durable.workflow.proxyActivities<typeof activities>();

    await submitForReview(orderId);

    // Pause indefinitely until a human approves or rejects
    const decision = await Durable.workflow.waitFor<{ approved: boolean }>('approval');

    return decision.approved;
    }

    // Later, from outside the workflow (e.g., an API handler):
    await client.workflow.signal('approval', { approved: true });
    // Fan-in: wait for multiple signals in parallel
    export async function gatherWorkflow(): Promise<[string, number]> {
    const [name, score] = await Promise.all([
    Durable.workflow.waitFor<string>('name-signal'),
    Durable.workflow.waitFor<number>('score-signal'),
    ]);
    return [name, score];
    }
    // Paired with hook: spawn work and wait for the result
    export async function orchestrator(input: string): Promise<string> {
    const signalId = `result-${Durable.workflow.random()}`;

    // Spawn a hook that will signal back when done
    await Durable.workflow.hook({
    taskQueue: 'processors',
    workflowName: 'processItem',
    args: [input, signalId],
    });

    // Wait for the hook to signal completion
    return await Durable.workflow.waitFor<string>(signalId);
    }

    Type Parameters

    • T

      The type of data expected in the signal payload.

    Parameters

    • signalId: string

      A unique signal identifier shared by the sender and receiver.

    Returns Promise<T>

    The data payload associated with the received signal.