Home > @aws/durable-execution-sdk-js > DurableContext > runInChildContext
Runs a function in a child context with isolated state and execution tracking
Signature:
runInChildContext<TOutput>(name: string | undefined, fn: ChildFunc<TOutput, TLogger>, config?: ChildConfig<TOutput>): DurablePromise<TOutput>;|
Parameter |
Type |
Description |
|---|---|---|
|
name |
string | undefined |
Step name for tracking and debugging |
|
fn |
ChildFunc<TOutput, TLogger> |
Function to execute in the child context |
|
config |
ChildConfig<TOutput> |
(Optional) Optional configuration for serialization and sub-typing |
Returns:
DurablePromise<TOutput>
{ChildContextError} When the child context function fails
const result = await context.runInChildContext(
"process-batch",
async (childCtx) => {
// Child context has its own step counter and state
const step1 = await childCtx.step("validate", async () => validate(data));
const step2 = await childCtx.step("transform", async () =>
transform(step1),
);
return step2;
},
{ subType: "batch-processor" },
);