# runWithRequest() function · @imqueue/rpc

Source: https://imqueue.org/api/rpc/latest/rpc.runwithrequest/
Published: 2026-08-04
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/rpc 3.5.3 — generated reference, not hand-written

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:**

```typescript
export declare function runWithRequest<T>(request: IMQRPCRequest, fn: () => T): T;
```

## Parameters


| Parameter | Type | Description |
| --- | --- | --- |
| request | [IMQRPCRequest](https://imqueue.org/api/rpc/latest/rpc.imqrpcrequest/) | the request to bind for this execution |
| fn | () => T | the work to run within the bound context |


**Returns:**

T

