• Combines hook() + waitFor() into a single call: spawns a hook function on a target workflow and suspends the current workflow until the hook signals completion. This is the recommended pattern for request/response communication between workflow threads.

    A signalId is automatically generated (or use the one you provide) and injected as the last argument to the hooked function as { signal: string, $durable: true }. The hook function must call Durable.workflow.signal(signalInfo.signal, result) to deliver its response back to the waiting workflow.

    • execChild spawns a new workflow job with its own lifecycle.
    • execHook runs within an existing workflow's job, in an isolated dimensional thread. This is lighter-weight and shares the parent job's data namespace.
    import { Durable } from '@hotmeshio/hotmesh';

    // Orchestrator: spawn a hook and await its result
    export async function reviewWorkflow(docId: string): Promise<string> {
    const verdict = await Durable.workflow.execHook<{ approved: boolean }>({
    taskQueue: 'reviewers',
    workflowName: 'reviewDocument',
    args: [docId],
    });

    return verdict.approved ? 'accepted' : 'rejected';
    }
    // The hooked function (runs on the 'reviewers' worker)
    export async function reviewDocument(
    docId: string,
    signalInfo?: { signal: string; $durable: boolean },
    ): Promise<{ approved: boolean }> {
    const { analyzeDocument } = Durable.workflow.proxyActivities<typeof activities>();
    const score = await analyzeDocument(docId);
    const result = { approved: score > 0.8 };

    // Signal the waiting workflow with the result
    if (signalInfo?.signal) {
    await Durable.workflow.signal(signalInfo.signal, result);
    }
    return result;
    }
    // With explicit signalId for traceability
    const result = await Durable.workflow.execHook<AnalysisResult>({
    taskQueue: 'analyzers',
    workflowName: 'runAnalysis',
    args: [datasetId],
    signalId: `analysis-${datasetId}`,
    });

    Type Parameters

    • T

      The type of data returned by the hook function's signal.

    Parameters

    • options: ExecHookOptions

      Hook configuration including target workflow and arguments.

    Returns Promise<T>

    The signal result from the hooked function.