Constructors

Properties

#abortCause: any
#aborted: boolean
#finalizers: (() => Promise<void>)[]

Type declaration

    • (): Promise<void>
    • Returns Promise<void>

#invocationHandles: Map<string, InvocationHandle<any>>
#resonate: Resonate
#resources: Map<string, any>
#stopAllPolling: boolean = false
childrenCount: number
invocationData: InvocationData
parent: undefined | Context
root: Context

Accessors

Methods

  • Adds a finalizer function to be executed at the end of the current context. Finalizers are run in reverse order of their definition (last-in, first-out).

    Parameters

    • fn: (() => Promise<void>)

      An asynchronous function to be executed as a finalizer. It should return a Promise that resolves to void.

        • (): Promise<void>
        • Returns Promise<void>

    Returns void

    Remarks

    Finalizer functions must be non fallible.

  • Creates a Promise that is resolved with an array of results when all of the provided Promises resolve, or rejected when any Promise is rejected.

    Type Parameters

    • T extends [] | readonly unknown[]

    Parameters

    • values: T

      An array of Promises.

    • opts: Partial<Options> = {}

      Optional options.

    Returns Promise<{
        -readonly [P in string | number | symbol]: Awaited<T[P<P>]>
    }>

    A new ResonatePromise.

  • Creates a Promise that is resolved with an array of results when all of the provided Promises resolve or reject.

    Type Parameters

    • T extends [] | readonly unknown[]

    Parameters

    • values: T

      An array of Promises.

    • opts: Partial<Options> = {}

      Optional options.

    Returns Promise<{
        -readonly [P in string | number | symbol]: PromiseSettledResult<Awaited<T[P<P>]>>
    }>

    A new Promise.

  • Creates a Promise that is fulfilled by the first given promise to be fulfilled, or rejected with an AggregateError.

    Type Parameters

    • T extends [] | readonly unknown[]

    Parameters

    • values: T

      An array of Promises.

    • opts: Partial<Options> = {}

      Optional options.

    Returns Promise<Awaited<Awaited<T[number]>>>

    A new ResonatePromise.

  • Invoke a Resonate function in detached mode. Functions must first be registered with Resonate. a detached invocation will not be implecitly awaited at the end of the current context, instead it will be "supervised" as a top level invocation.

    Type Parameters

    • R

      The return type of the function.

    Parameters

    • name: string

      The function name.

    • id: string

      A unique id for the function invocation.

    • Rest ...argsWithOverrides: any[]

      The function arguments and options overrides.

    Returns Promise<InvocationHandle<R>>

    A Res.

  • Retrieves a resource by name from the current context or its parent contexts.

    Type Parameters

    • R

      The expected type of the resource.

    Parameters

    • name: string

      The unique string identifier of the resource to retrieve.

    Returns undefined | R

    The resource of type R if found, or undefined if not found.

    This method searches for a resource in the following order:

    1. In the current context.
    2. If not found, it recursively searches in parent contexts.
    3. Returns undefined if the resource is not found in any context.

    Remarks

    The method uses type assertion to cast the resource to type R. Ensure that the type parameter R matches the actual type of the stored resource to avoid runtime type errors.

  • Creates a Promise that is resolved or rejected when any of the provided Promises are resolved or rejected.

    Type Parameters

    • T extends [] | readonly unknown[]

    Parameters

    • values: T

      An array of Promises.

    • opts: Partial<Options> = {}

      Optional options.

    Returns Promise<Awaited<T[number]>>

    A new ResonatePromise.

  • Invoke a remote function.

    Type Parameters

    • R

      The return type of the remote function.

    Parameters

    • funcId: string
    • args: any

      The arguments to pass to the remote function.

    • Optional opts: PartialOptions

      Optional options.

    Returns Promise<R>

    A promise that resolves to the resolved value of the remote function.

  • Invoke a function.

    Type Parameters

    • F extends Func

      The type of the function.

    Parameters

    Returns Promise<Return<F>>

    A promise that resolves to the return value of the function.

  • Sets a named resource for the current context and optionally adds a finalizer.

    Parameters

    • name: string

      A unique string identifier for the resource.

    • resource: any

      The resource to be stored. Can be of any type.

    • Optional finalizer: (() => Promise<void>)

      Optional. An asynchronous function to be executed when the context ends. Finalizers are run in reverse order of their addition to the context and must not fail.

        • (): Promise<void>
        • Returns Promise<void>

    Returns void

    Throws

    Throws an error if a resource with the same name already exists in the current context.

    This method associates a resource with a unique name in the current context. If a finalizer is provided, it will be executed when the context ends. Finalizers are useful for cleanup operations, such as closing connections or freeing resources.

  • Durable version of sleep. Sleep for the specified time (ms).

    Parameters

    • ms: number

      Amount of time to sleep in milliseconds.

    Returns Promise<void>

    A Promise that resolves after the specified time has elapsed.