-
Notifications
You must be signed in to change notification settings - Fork 0
timeout
awekrx edited this page May 29, 2026
·
1 revision
import { timeout } from '@dev-suite/decorators/timeout'
method
Fail long-running async methods after a fixed time budget.
-
Promise.racetimeout wrappers in each method - Custom watchdog utilities in service code
class FileService {
async upload(file: Buffer) {
return Promise.race([
this.remote.upload(file),
new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), 5000)),
]);
}
}import { timeout } from '@dev-suite/decorators/timeout';
class FileService {
@timeout({ ms: 5000, message: 'Upload timeout' })
async upload(file: Buffer) {
return this.remote.upload(file);
}
}- Timeout behavior is consistent across methods.
- Eliminates repeated
Promise.racecode.
class ReportService {
async build(id: string) {
const task = this.engine.build(id);
const timeoutGuard = new Promise((_, reject) => setTimeout(() => reject(new Error('build timeout')), 2000));
return Promise.race([task, timeoutGuard]);
}
}import { timeout } from '@dev-suite/decorators/timeout';
class ReportService {
@timeout({ ms: 2000 })
async build(id: string) {
return this.engine.build(id);
}
}- Simple to tune per method with one option change.
- Keeps method logic focused on work, not guards.