Wraps a function so it always runs outside any active method or execution context.
When the wrapped function is called, beginContext checks whether
MethodContextService or ExecutionContextService currently have an active
scope and, if so, escapes each one with runOutOfContext before invoking run.
This prevents accidental context leakage from a caller into a logically independent
operation (e.g. an internal runner that must establish its own fresh context).
The returned wrapper preserves the original function's parameter and return types,
so it is a transparent drop-in replacement.
Wraps a function so it always runs outside any active method or execution context.
When the wrapped function is called,
beginContextchecks whetherMethodContextServiceorExecutionContextServicecurrently have an active scope and, if so, escapes each one withrunOutOfContextbefore invokingrun. This prevents accidental context leakage from a caller into a logically independent operation (e.g. an internal runner that must establish its own fresh context).The returned wrapper preserves the original function's parameter and return types, so it is a transparent drop-in replacement.
Example