fix(classes): cleanup resources, add cancellable timeouts, and fix bugs in several core utility classes
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user