fix(servicemanager): cancel startup timeout once service initialization completes

This commit is contained in:
2026-03-23 14:59:59 +00:00
parent e25271f9db
commit 820811cca2
4 changed files with 17 additions and 8 deletions

View File

@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/taskbuffer',
version: '8.0.1',
version: '8.0.2',
description: 'A flexible task management library supporting TypeScript, allowing for task buffering, scheduling, and execution with dependency management.'
}

View File

@@ -82,12 +82,15 @@ export class ServiceManager {
// Enforce global startup timeout
if (this.options.startupTimeoutMs) {
await Promise.race([
startupPromise,
plugins.smartdelay.delayFor(this.options.startupTimeoutMs).then(() => {
throw new Error(`${this.name}: global startup timeout exceeded (${this.options.startupTimeoutMs}ms)`);
}),
]);
const timeout = new plugins.smartdelay.Timeout(this.options.startupTimeoutMs);
const timeoutPromise = timeout.promise.then(() => {
throw new Error(`${this.name}: global startup timeout exceeded (${this.options.startupTimeoutMs}ms)`);
});
try {
await Promise.race([startupPromise, timeoutPromise]);
} finally {
timeout.cancel();
}
} else {
await startupPromise;
}