Home > @imqueue/rpc > runWithRequest

runWithRequest() function

Runs the given function with request bound to the current async execution context, so any code reached from it (and its asynchronous continuations) can access the in-flight request's metadata via currentMetadata() without threading it through call signatures.

The binding is scoped to the function: it is established for the duration of the call and automatically removed afterwards, which keeps concurrent requests isolated from one another.

Signature:

export declare function runWithRequest<T>(request: IMQRPCRequest, fn: () => T): T;

Parameters

Parameter

Type

Description

request

IMQRPCRequest

the request to bind for this execution

fn

() => T

the work to run within the bound context {T}

Returns:

T