The @Timeout decorator is used to schedule a method to execute once after a specific delay, behaving like a standard setTimeout.
You can provide the delay in milliseconds, and optionally provide a unique name for the timeout task.
Overloads:
@Timeout(timeout: number): Schedules a task with the specified delay.@Timeout(name: string, timeout: number): Schedules a named task with the specified delay.
import { Timeout } from '@nestjs/schedule';
class MyService {
@Timeout(5000)
handleTimeout() {
// This runs once after 5 seconds
}
@Timeout('my-custom-task', 10000)
handleNamedTimeout() {
// This runs once after 10 seconds and is identified by 'my-custom-task'
}
}