• Emits pub/sub events to the event bus, allowing workflows to broadcast messages to external subscribers. Each entry in the events map is published as a separate message on the corresponding topic.

    By default (config.once = true), events are emitted exactly once per workflow execution — the isSideEffectAllowed guard prevents re-emission on replay. Set config.once = false to emit on every re-execution (rarely needed).

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

    // Emit a domain event when an order is processed
    export async function orderWorkflow(orderId: string): Promise<void> {
    const { processOrder } = Durable.workflow.proxyActivities<typeof activities>();
    const result = await processOrder(orderId);

    await Durable.workflow.emit({
    'order.completed': { orderId, total: result.total },
    'analytics.event': { type: 'order', orderId },
    });
    }
    // Emit progress events during a long-running workflow
    export async function batchWorkflow(items: string[]): Promise<void> {
    const { processItem } = Durable.workflow.proxyActivities<typeof activities>();

    for (let i = 0; i < items.length; i++) {
    await processItem(items[i]);
    await Durable.workflow.emit(
    { 'batch.progress': { completed: i + 1, total: items.length } },
    { once: false }, // emit on every execution (progress updates)
    );
    }
    }

    Parameters

    • events: StringAnyType

      A mapping of topic to message payload.

    • Optionalconfig: {
          once: boolean;
      } = ...

      If true, events emit only once (idempotent).

      • once: boolean

    Returns Promise<boolean>

    true after emission completes.