Static
allStatic
didChecks if an error is a HotMesh reserved error type that indicates a HotMesh interruption rather than a true error condition.
When this returns true, you can safely return rethrow the error. The workflow engine will handle the interruption automatically.
The error to check
true if the error is a HotMesh interruption
Static
didStatic
emitEmits events to the event bus provider. Topics are prefixed with the quorum namespace.
A mapping of topic => message to publish.
Optional
config: { If once
is true, events are emitted only once.
True after emission completes.
Static
enrichAdds custom user data to the backend workflow record (writes to HASH). Runs exactly once during workflow execution.
Key-value fields to enrich the workflow record.
True when enrichment is completed.
Static
entityStatic
execSpawns a child workflow and awaits the result, or if await
is false, returns immediately.
Workflow options.
Result of the child workflow.
Static
execExecutes a hook function and awaits the signal response.
This is a convenience method that combines hook()
and waitFor()
operations.
Signal Injection: The signalId
is automatically injected as the LAST argument
to the hooked function. The hooked function should check for this signal parameter
and emit the signal when processing is complete.
This behaves like execChild
but targets the existing workflow instead of
spawning a new workflow.
Hook configuration with signal ID.
The signal result from the hooked function.
// Execute a hook and await its signal response
const result = await MemFlow.workflow.execHook({
taskQueue: 'processing',
workflowName: 'processData',
args: ['user123', 'batch-process'],
signalId: 'processing-complete'
});
// The hooked function receives the signal as the last argument:
export async function processData(userId: string, processType: string, signalInfo?: { signal: string }) {
// ... do processing work ...
const result = { userId, processType, status: 'completed' };
// Check if called via execHook (signalInfo will be present)
if (signalInfo?.signal) {
await MemFlow.workflow.signal(signalInfo.signal, result);
}
return result;
}
// Alternative pattern - check if last arg is signal object
export async function myHookFunction(arg1: string, arg2: number, ...rest: any[]) {
// ... process arg1 and arg2 ...
const result = { processed: true, data: [arg1, arg2] };
// Check if last argument is a signal object
const lastArg = rest[rest.length - 1];
if (lastArg && typeof lastArg === 'object' && lastArg.signal) {
await MemFlow.workflow.signal(lastArg.signal, result);
}
return result;
}
Static
executeSpawns a child workflow and awaits the result, or if await
is false, returns immediately.
Workflow options.
Result of the child workflow.
Static
getReturns the current workflow context, restored from storage.
The current workflow context.
Static
hookSpawns a hook from the main thread or a hook thread. If entity/workflowName are not provided, defaults to the current workflow.
Hook configuration options.
The resulting hook/stream ID.
Static
interruptInterrupts a running job by sending an interruption request.
The ID of the job to interrupt.
Additional interruption options.
Result of the interruption, if any.
Static
isStatic
proxyProvides a proxy for defined activities, ensuring deterministic replay and retry.
Optional
options: ActivityConfigOptional activity config (includes retryPolicy).
A proxy to call activities as if local, but durably managed by the workflow.
Static
randomReturns a deterministic random number between 0 and 1. The number is derived from the current execution index, ensuring deterministic replay.
A deterministic pseudo-random number between 0 and 1.
Static
searchStatic
signalSends a signal payload to any paused workflow thread awaiting this signal. This method is commonly used to coordinate between workflows, hook functions, and external events.
Unique signal identifier that matches a waitFor() call.
The payload to send with the signal.
The resulting hook/stream ID.
// Basic usage - send a simple signal with data
await MemFlow.workflow.signal('signal-id', { name: 'WarmMash' });
// Hook function signaling completion
export async function exampleHook(name: string): Promise<void> {
const result = await processData(name);
await MemFlow.workflow.signal('hook-complete', { data: result });
}
// Signal with complex data structure
await MemFlow.workflow.signal('process-complete', {
status: 'success',
data: { id: 123, name: 'test' },
timestamp: new Date().toISOString()
});
Static
sleepSleeps the workflow for a specified duration, deterministically. On replay, it will not actually sleep again, but resume after sleep.
A human-readable duration string (e.g., '1m', '2 hours', '30 seconds').
The resolved duration in seconds.
// Basic usage - sleep for a specific duration
await MemFlow.workflow.sleepFor('2 seconds');
// Using with Promise.all for parallel operations
const [greeting, timeInSeconds] = await Promise.all([
someActivity(name),
MemFlow.workflow.sleepFor('1 second')
]);
// Multiple sequential sleeps
await MemFlow.workflow.sleepFor('1 seconds'); // First pause
await MemFlow.workflow.sleepFor('2 seconds'); // Second pause
Static
startSpawns a child workflow and returns the child Job ID without awaiting its completion.
Workflow options.
The child job ID.
Static
traceExecutes a distributed trace, outputting the provided attributes to the telemetry sink (e.g. OpenTelemetry).
This trace will only run once per workflow execution by default.
Key-value attributes to attach to the trace.
Optional
config: { If once
is true, trace only runs once.
True if tracing succeeded, otherwise false.
Static
waitPauses the workflow until a signal with the given signalId
is received.
This method is commonly used to coordinate between the main workflow and hook functions,
or to wait for external events.
A unique signal identifier shared by the sender and receiver.
The data payload associated with the received signal.
// Basic usage - wait for a single signal
const payload = await MemFlow.workflow.waitFor<PayloadType>('abcdefg');
// Wait for multiple signals in parallel
const [signal1, signal2] = await Promise.all([
MemFlow.workflow.waitFor<Record<string, any>>('signal1'),
MemFlow.workflow.waitFor<Record<string, any>>('signal2')
]);
// Typical pattern with hook functions
// In main workflow:
await MemFlow.workflow.waitFor<ResponseType>('hook-complete');
// In hook function:
await MemFlow.workflow.signal('hook-complete', { data: result });
The WorkflowService class provides a set of static methods to be used within a workflow function. These methods ensure deterministic replay, persistence of state, and error handling across re-entrant workflow executions.
Example