Skip to main content

Timeouts

The engine also supports timeouts for an execution context. This is, when a execution (request) takes longer than a specified time, it will be automatically canceled and an error will be thrown. This is useful to prevent long-running executions from blocking the system.

Each transport has its own timeout configuration, enabling you to set different timeouts for different transports. The timeout can be configured in the transport options when creating the transport instance. Also, when using the @Timeout() decorator, you can specify a timeout for a specific step or method. This allows you to have fine-grained control over the timeout behavior of your engine steps. The @NoTimeout() decorator can be used to disable the timeout for a specific step or method, even if the transport has a timeout configured.

The engine also provides a default timeout for all transports (5000ms) in case you enable the timeout feature but do not specify a timeout for a specific transport or step.

Important, the @Timeout() and @NoTimeout() decorators will only work if the transport has enabled the timeout feature.

Example of Timeouts in Http Transport​

app.ts
app.use(
HttpPlugin,
HttpPluginOptionsFactory.create({
...
timeout: true,
timeoutOptions: {
time: 3000, // 3 seconds in case no decorator is used. 5 seconds is the default timeout for all transports.
message: (time: number) => `Request timeout after ${time} ms`
}
...
})
);
example-controller.ts
@Timeout(2000)
@Controller('timeouts')
export class TimeoutController {
@Get()
async exampleTimeout() {...}

@Get('no-timeout')
@NoTimeout()
async exampleNoTimeout() {...}

@Timeout(10) // 10 milliseconds
@Get('throw-timeout')
async exampleThrowTimeout() {...}
}