Skip to content

Latest commit

 

History

History
94 lines (57 loc) · 1.76 KB

File metadata and controls

94 lines (57 loc) · 1.76 KB

Home > @aws/durable-execution-sdk-js > DurableContext > runInChildContext

DurableContext.runInChildContext() method

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>;

Parameters

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>

Exceptions

{ChildContextError} When the child context function fails

Example

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" },
);