Skip to content

timeout

Races the pipeline against a configurable deadline. On timeout, sets the response status and detail via closure, then destroys the request stream. The timer is cleared automatically when the response finishes.

Pipeline stage: Cross-cutting

import { timeout } from "@centralping/ergo";
OptionTypeDefaultDescription
msnumber30000 (30s)Timeout duration in milliseconds
statusCodenumber408HTTP status on timeout (typically 408 or 504)

The middleware is side-effect only — it does not produce an accumulator value. On timeout it sets responseAcc.statusCode and responseAcc.detail directly.

StatusCondition
408 Request TimeoutDefault — deadline exceeded
504 Gateway TimeoutWhen configured with statusCode: 504

The error detail is: Request timed out after ${ms}ms.

import { compose, timeout } from "@centralping/ergo";
const pipeline = compose(
timeout({ ms: 10_000, statusCode: 504 }),
async (req, res, acc) => ({
response: { body: await slowOperation(), statusCode: 200 },
}),
);

See the auto-generated timeout API docs.