# withCallTimeout() function · @imqueue/rpc

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

Runs `fn` with a time limit of its own for every client call made inside it, in place of the client's [IMQClientOptions.callTimeout](https://imqueue.org/api/rpc/latest/rpc.imqclientoptions.calltimeout/).

**Signature:**

```typescript
export declare function withCallTimeout<T>(ms: number, fn: () => T): T;
```

## Parameters


| Parameter | Type | Description |
| --- | --- | --- |
| ms | number | the limit in milliseconds, as `callTimeout` takes it: `0`, a negative number or `Infinity` means no limit |
| fn | () => T | the work whose calls get this limit |


**Returns:**

T

what `fn` returns

## Remarks

The scope covers every call made inside it, on any client, including calls made after an `await`, in a callback or timer started inside it, and calls a local (in-process) service makes while answering one. A scope inside a scope replaces it until the inner one ends. A requested [IMQDelay](https://imqueue.org/api/rpc/latest/rpc.imqdelay/) still adds to the limit. Outside a scope, each client uses its own `callTimeout`, exactly as before. Nothing about the call on the wire changes: the limit is the caller's alone.

## Example


```typescript
const report = await withCallTimeout(120000, () => reports.build(id));
```

