Function asyncTrampoline

  • Executes an asynchronous trampoline computation until a final (non-thunk) result is obtained.

    This function repeatedly invokes asynchronous deferred computations (thunks) in an iterative loop. Each thunk may return either a Trampoline or a Promise<Trampoline>.

    It ensures that asynchronous recursive functions can run without growing the call stack, making it suitable for stack-safe async recursion.

    Type Parameters

    • T

      The type of the final result.

    Parameters

    • initial: Trampoline<T> | Promise<Trampoline<T>>

      The initial Trampoline or Promise of Trampoline to start execution from.

    Returns Promise<T>

    A Promise that resolves to the final result (a non-thunk value).