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
Section titled “Import”import { timeout } from "@centralping/ergo";Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
ms | number | 30000 (30s) | Timeout duration in milliseconds |
statusCode | number | 408 | HTTP status on timeout (typically 408 or 504) |
Return Value
Section titled “Return Value”The middleware is side-effect only — it does not produce an accumulator
value. On timeout it sets responseAcc.statusCode and
responseAcc.detail directly.
Error Responses
Section titled “Error Responses”| Status | Condition |
|---|---|
| 408 Request Timeout | Default — deadline exceeded |
| 504 Gateway Timeout | When 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 }, }),);router.get("/slow-report", { timeout: { ms: 60_000 }, execute: async (req, res, acc) => ({ response: { body: await generateReport() }, }),});API Reference
Section titled “API Reference”See the auto-generated timeout API docs.