Skip to content

Connectum API Reference / @connectum/interceptors / timeout / createTimeoutInterceptor

Function: createTimeoutInterceptor() ​

createTimeoutInterceptor(options?): Interceptor

Defined in: timeout.ts:72

Create timeout interceptor

Prevents requests from hanging indefinitely by enforcing a timeout. Propagates cancellation to downstream work and rejects with DeadlineExceeded when its own deadline expires. Caller cancellation preserves its ConnectError reason, or becomes Canceled when the caller supplies another reason. Handlers and I/O must observe the signal to stop work; cancellation does not roll back side effects or forcibly stop signal-unaware code.

Streaming is skipped by default. With skipStreaming=false, the timeout covers opening the response, not subsequent iteration. Caller cancellation continues to reach an opened stream after the opening timer has been cleared, until the reader is done with the stream (read to the end, failed, or closed early); then the interceptor lets go of the caller's signal. A stream nobody iterates keeps following the caller's signal until that signal aborts.

duration must be an integer from 1 to 2147483647 milliseconds (the ceiling of the platform timer, above which it would fire after 1 ms); anything else throws at construction (TypeError for a non-number, RangeError otherwise).

Parameters ​

options? ​

TimeoutOptions = {}

Timeout options

Returns ​

Interceptor

ConnectRPC interceptor

Examples ​

Server-side usage with createServer

typescript
import { createServer } from '@connectum/core';
import { createTimeoutInterceptor } from '@connectum/interceptors';
import { myRoutes } from './routes.js';

const server = createServer({
  services: [myRoutes],
  interceptors: [
    createTimeoutInterceptor({
      duration: 30000,      // 30 second timeout
      skipStreaming: true,  // Skip streaming calls
    }),
  ],
});

await server.start();

Client-side usage with transport

typescript
import { createConnectTransport } from '@connectrpc/connect-node';
import { createTimeoutInterceptor } from '@connectum/interceptors';

const transport = createConnectTransport({
  baseUrl: 'http://localhost:5000',
  httpVersion: '1.1',
  interceptors: [
    createTimeoutInterceptor({ duration: 10000 }),
  ],
});