Make Conversion.cancel() cause execute() to throw (closes #271)

This commit is contained in:
Vanilagy
2026-01-12 15:13:00 +01:00
parent 78e78e5b4f
commit 24af125415
4 changed files with 22 additions and 4 deletions
+18 -2
View File
@@ -822,7 +822,7 @@ export class Conversion {
}
if (this._canceled) {
await new Promise(() => {}); // Never resolve
throw new ConversionCanceledError();
}
await this.output.finalize();
@@ -832,7 +832,10 @@ export class Conversion {
}
}
/** Cancels the conversion process. Does nothing if the conversion is already complete. */
/**
* Cancels the conversion process, causing any ongoing `execute` call to throw a `ConversionCanceledError`.
* Does nothing if the conversion is already complete.
*/
async cancel() {
if (this.output.state === 'finalizing' || this.output.state === 'finalized') {
return;
@@ -1589,6 +1592,19 @@ export class Conversion {
}
}
/**
* Thrown when a conversion couldn't complete due to being canceled.
* @group Conversion
* @public
*/
export class ConversionCanceledError extends Error {
/** Creates a new {@link ConversionCanceledError}. */
constructor(message = 'Conversion has been canceled.') {
super(message);
this.name = 'ConversionCanceledError';
}
}
const MAX_TIMESTAMP_GAP = 5;
/**