fix(classes): cleanup resources, add cancellable timeouts, and fix bugs in several core utility classes

This commit is contained in:
2026-03-01 19:21:42 +00:00
parent 597e9e15c3
commit ddf4e698c9
11 changed files with 197 additions and 35 deletions

View File

@@ -97,13 +97,20 @@ export class AsyncExecutionStack {
private async executeExclusiveSlot(slot: IExecutionSlot<any>) {
try {
if (slot.timeout) {
const result = await Promise.race([
slot.funcToExecute(),
plugins.smartdelay.delayFor(slot.timeout).then(() => {
throw new Error('Timeout reached');
}),
]);
slot.executionDeferred.resolve(result);
const timeoutInstance = new plugins.smartdelay.Timeout(slot.timeout);
try {
const result = await Promise.race([
slot.funcToExecute(),
timeoutInstance.promise.then(() => {
throw new Error('Timeout reached');
}),
]);
timeoutInstance.cancel();
slot.executionDeferred.resolve(result);
} catch (error) {
timeoutInstance.cancel();
throw error;
}
} else {
const result = await slot.funcToExecute();
slot.executionDeferred.resolve(result);
@@ -120,11 +127,18 @@ export class AsyncExecutionStack {
try {
// execute with optional timeout
if (slot.timeout) {
const result = await Promise.race([
slot.funcToExecute(),
plugins.smartdelay.delayFor(slot.timeout).then(() => { throw new Error('Timeout reached'); }),
]);
slot.executionDeferred.resolve(result);
const timeoutInstance = new plugins.smartdelay.Timeout(slot.timeout);
try {
const result = await Promise.race([
slot.funcToExecute(),
timeoutInstance.promise.then(() => { throw new Error('Timeout reached'); }),
]);
timeoutInstance.cancel();
slot.executionDeferred.resolve(result);
} catch (error) {
timeoutInstance.cancel();
throw error;
}
} else {
const result = await slot.funcToExecute();
slot.executionDeferred.resolve(result);