Function beginTime

Wraps a function to execute it outside of the current execution context if one exists.

This utility ensures that the wrapped function runs in isolation from any existing ExecutionContext, preventing context leakage and unintended context sharing between async operations.

const myFunction = async (param: string) => {
// This code will run outside of any ExecutionContext
return param.toUpperCase();
};

const wrappedFunction = beginTime(myFunction);
const result = wrappedFunction('hello'); // Returns 'HELLO'
// Usage with trycatch wrapper
const safeFunction = trycatch(
beginTime(async (id: number) => {
// Function body runs isolated from parent context
return await fetchData(id);
})
);
  • Type Parameters

    • T extends (...args: any[]) => any

      Function type with any parameters and return type

    Parameters

    • run: T

      The function to be wrapped and executed outside of context

    Returns (...args: Parameters<T>) => ReturnType<T>

    A curried function that accepts the original function's parameters and executes it outside of the current context if one exists