Child runs
A durable function can start another workflow as a child run: a canvas workflow, or another durable function. The child is an ordinary run with its own page, linked to its parent, and its result comes back to the function.
Start a child and wait for it
const shipment = await ctx.child('fulfillment', {
input: { orderId: order.id },
version: 'active',
});
- The first argument is a workflow key, or a durable function exported from the same project.
versionis'active'(the default), a version such as'v7', or an alias such as'@canary'. The resolved version is recorded, so moving an alias later does not affect a child that is already running.- If the child fails,
ctx.childthrows aChildRunFailurewhosecauseexplains why.
Start a child without waiting
const handle = await ctx.startChild('send-welcome-series', { input: { userId } });
// later, if needed
const result = await handle.result();
When the parent ends
The parent-close policy decides what happens to a child that is still running when its parent finishes, fails or is cancelled:
| Policy | Effect |
|---|---|
TERMINATE | The child is terminated. Default for ctx.child |
ABANDON | The child keeps running on its own. Default for ctx.startChild |
REQUEST_CANCEL | The child is asked to cancel, so its own cleanup runs |
Set it with parentClosePolicy in the options.
From the canvas
The Code workflow node runs a durable function as a child of a canvas run and waits for it. Its output is the function's return value. If the function fails, the node fails with the function's error type, and the node's own error settings decide what happens next. With Wait for completion off, the node continues at once and the child outlives the parent unless you set a parent-close policy.
Child runs of both kinds count toward the same nesting limit as sub-workflows: ten levels.