Dex TypeScript SDK 1.30.0
    Preparing search index...

    Interface AsyncContext

    Adds asynchronous progress reporting to a Step invocation Context.

    Annotate an async waitFor, execute, or Flow timeout handler with AsyncContext when it records heartbeats. RPC handlers receive Context and cannot record heartbeats.

    interface AsyncContext {
        attempt: number;
        cancellationSignal: AbortSignal;
        deadline: Date | undefined;
        firstAttemptAt: Date;
        flowId: string;
        flowStartedAt: Date;
        fromStepExecutionId: string;
        recoveryError: RecoveryErrorInfo | undefined;
        runId: string;
        stepExecutionId: string;
        attributeMapKeys(attribute: AttributeMap<unknown>): readonly string[];
        channelMapKeys(channel: ChannelMap<unknown>): readonly string[];
        channelResults<T>(
            channel: Channel<T> | ChannelMap<T>,
            instance?: string,
        ): readonly T[];
        channelSize(
            channel: Channel<unknown> | ChannelMap<unknown>,
            instance?: string,
        ): number;
        deleteAttribute(
            attribute: AttributeMap<unknown> | Attribute<unknown>,
            instance?: string,
        ): void;
        deleteChannelMessage(
            channel: Channel<unknown> | ChannelMap<unknown>,
            messageId: string,
            instance?: string,
        ): void;
        getAttribute<T>(
            attribute: Attribute<T> | AttributeMap<T>,
            instance?: string,
        ): T;
        getLastHeartbeatValue<T = unknown>(codec?: Codec<T>): T | undefined;
        getStepExecutionLocal<T>(key: string, codec: Codec<T>): T | undefined;
        hasLastHeartbeatValue(): boolean;
        hasTimerFired(index?: number): boolean;
        pendingChannelMessages<T>(
            channel: Channel<T> | ChannelMap<T>,
            instance?: string,
        ): readonly ChannelMessage<T>[];
        publish<T>(
            channel: Channel<T> | ChannelMap<T>,
            value: T,
            instance?: string,
        ): void;
        recordEvent<T>(name: string, value: T, codec: Codec<T>): void;
        recordHeartbeat<T>(value: T | undefined, codec?: Codec<T>): Promise<void>;
        setAttribute<T>(
            attribute: Attribute<T> | AttributeMap<T>,
            value: T,
            instance?: string,
        ): void;
        setStepExecutionLocal<T>(key: string, value: T, codec: Codec<T>): void;
        waitForMethodFailed(): boolean;
        writeStream<T>(stream: Stream<T>, value: T): void;
    }

    Hierarchy (View Summary)

    Index

    Properties

    attempt: number

    One-based handler retry attempt number.

    cancellationSignal: AbortSignal

    Signal aborted when Dex cancels the active Worker call.

    Pass it to abort-aware APIs or inspect it at natural CPU-work boundaries. JavaScript cannot forcibly stop synchronous code, and cancellation cannot make external effects atomic.

    deadline: Date | undefined

    Absolute UTC deadline of the current Step method attempt, or undefined when absent.

    Available during waitFor, execute, and Flow timeout handlers. RPC handlers have no deadline. A shorter remaining RetryPolicy total duration limits this value. Each retry receives its own effective deadline. Dates have millisecond precision.

    Compute the remaining attempt budget in milliseconds inside a handler:

    const deadline = context.deadline;
    if (deadline !== undefined) {
    const remainingMs = deadline.getTime() - Date.now();
    }
    firstAttemptAt: Date

    UTC timestamp of the first handler attempt.

    flowId: string

    Stable application Flow ID shared across runs.

    flowStartedAt: Date

    UTC timestamp at which the current Flow run started.

    fromStepExecutionId: string

    Predecessor Step execution ID, or an empty string at Flow start.

    recoveryError: RecoveryErrorInfo | undefined

    Final failure that selected this recovery path, or undefined when absent.

    runId: string

    Current server-assigned run ID.

    stepExecutionId: string

    Current Step type and execution number encoded by Dex.

    Methods

    • Returns effective decoded AttributeMap keys in ascending order.

      Parameters

      • attribute: AttributeMap<unknown>

        Registered AttributeMap definition.

      Returns readonly string[]

      Keys visible after decision-local writes and deletions.

    • Returns decoded non-empty ChannelMap keys in ascending order during an RPC.

      Parameters

      • channel: ChannelMap<unknown>

        Registered ChannelMap definition.

      Returns readonly string[]

      Keys including publications buffered by the current RPC.

    • Returns values selected by the satisfied Channel condition.

      Type Parameters

      • T

        Channel element type.

      Parameters

      • channel: Channel<T> | ChannelMap<T>

        Registered singleton or map definition.

      • Optionalinstance: string

        Required ChannelMap instance; omitted for a singleton.

      Returns readonly T[]

      Ordered values for this Step execution.

    • Returns a Channel's current queued value count.

      Parameters

      • channel: Channel<unknown> | ChannelMap<unknown>

        Registered singleton or map definition.

      • Optionalinstance: string

        Required ChannelMap instance; omitted for a singleton.

      Returns number

      Non-negative queued value count.

    • Stages deletion of an Attribute value.

      Parameters

      • attribute: AttributeMap<unknown> | Attribute<unknown>

        Registered singleton or map definition.

      • Optionalinstance: string

        Required AttributeMap instance; omitted for a singleton.

      Returns void

    • Stages deletion of one pending Channel message from an RPC handler.

      Parameters

      • channel: Channel<unknown> | ChannelMap<unknown>

        Registered singleton or map definition.

      • messageId: string

        Non-empty server-assigned message ID.

      • Optionalinstance: string

        Required ChannelMap instance; omitted for a singleton.

      Returns void

    • Reads a typed Attribute from decision state.

      Type Parameters

      • T

        Attribute value type.

      Parameters

      • attribute: Attribute<T> | AttributeMap<T>

        Registered singleton or map definition.

      • Optionalinstance: string

        Required AttributeMap instance; omitted for a singleton.

      Returns T

      The decoded current value.

    • Decodes heartbeat details recorded by the previous regular-activity attempt.

      The codec must match the one passed to AsyncContext.recordHeartbeat. When omitted, values use JSON encoding. Call Context.hasLastHeartbeatValue to distinguish an absent Value from a present null value, because both decode to undefined.

      Type Parameters

      • T = unknown

        Expected heartbeat value type.

      Parameters

      • Optionalcodec: Codec<T>

        Codec used to decode the Value; omitted for JSON.

      Returns T | undefined

      The decoded value, or undefined when no Value is present.

    • Reads process-local data for this Step execution.

      Type Parameters

      • T

        Expected local value type.

      Parameters

      • key: string

        Key used when storing the value.

      • codec: Codec<T>

        Codec used to decode the value.

      Returns T | undefined

      The value, or undefined after absence or worker restart.

    • Reports whether a previous regular-activity attempt recorded heartbeat details.

      Returns boolean

      Whether a last heartbeat Value is present.

    • Reports whether a Timer made the current Wait ready.

      Parameters

      • Optionalindex: number

        Optional zero-based Timer index; checks any Timer when omitted.

      Returns boolean

      Whether the selected Timer fired.

    • Returns loaded pending Channel messages in FIFO order.

      Type Parameters

      • T

        Channel element type.

      Parameters

      • channel: Channel<T> | ChannelMap<T>

        Registered singleton or map definition selected by the RPC.

      • Optionalinstance: string

        Required ChannelMap instance; omitted for a singleton.

      Returns readonly ChannelMessage<T>[]

      Immutable pending message IDs and decoded values.

    • Stages one typed Channel publication.

      Type Parameters

      • T

        Channel element type.

      Parameters

      • channel: Channel<T> | ChannelMap<T>

        Registered singleton or map definition.

      • value: T

        Value to append.

      • Optionalinstance: string

        Required ChannelMap instance; omitted for a singleton.

      Returns void

    • Stages an application event in the current handler result.

      Type Parameters

      • T

        Event payload type.

      Parameters

      • name: string

        Non-empty diagnostic event name.

      • value: T

        Event payload.

      • codec: Codec<T>

        Payload codec.

      Returns void

    • Records heartbeat progress for the current Step method attempt.

      Passing undefined explicitly clears persisted heartbeat details. Every other value produces a present Value; omitted codecs use JSON. The Promise resolves when grpc-js accepts the frame, not when Temporal persists it. Local activities ignore heartbeat frames.

      Type Parameters

      • T

        Heartbeat value type.

      Parameters

      • value: T | undefined

        Value to persist, or undefined to clear existing details.

      • Optionalcodec: Codec<T>

        Codec used to encode the Value; omitted for JSON.

      Returns Promise<void>

      A Promise resolved after the Worker accepts the output frame locally. All failures reject this Promise; this method never throws synchronously.

      The Promise rejects if the task is inactive, finished, cancelled, or its stream is closed.

      The Promise rejects when the Context cannot record heartbeats.

      The Promise rejects if the heartbeat value cannot be encoded.

    • Stages an Attribute write in the current decision.

      Type Parameters

      • T

        Attribute value type.

      Parameters

      • attribute: Attribute<T> | AttributeMap<T>

        Registered singleton or map definition.

      • value: T

        Typed value to persist.

      • Optionalinstance: string

        Required AttributeMap instance; omitted for a singleton.

      Returns void

    • Stores process-local data for this Step execution; it is not durable.

      Type Parameters

      • T

        Local value type.

      Parameters

      • key: string

        Non-empty execution-scoped key.

      • value: T

        Value retained in worker memory.

      • codec: Codec<T>

        Codec used to serialize the local value when required.

      Returns void

    • Reports whether waitFor failed before the current execute call.

      Returns boolean

      Whether failure policy proceeded to execution.

    • Appends one immediate best-effort Stream message.

      Type Parameters

      • T

        Stream message type.

      Parameters

      • stream: Stream<T>

        Stream registered by the current Flow type.

      • value: T

        Typed message to append.

      Returns void