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;
}
Executes a hook function and awaits the signal response. This is a convenience method that combines
hook()
andwaitFor()
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.