mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-03 13:53:53 +02:00
Make Conversion.cancel() cause execute() to throw (closes #271)
This commit is contained in:
+2
-1
@@ -100,6 +100,7 @@
|
|||||||
},
|
},
|
||||||
*/
|
*/
|
||||||
video: () => ({
|
video: () => ({
|
||||||
|
forceTranscode: true,
|
||||||
allowRotationMetadata: false,
|
allowRotationMetadata: false,
|
||||||
//width: 720,
|
//width: 720,
|
||||||
//frameRate: 30,
|
//frameRate: 30,
|
||||||
@@ -181,7 +182,7 @@
|
|||||||
},
|
},
|
||||||
trim: {
|
trim: {
|
||||||
start: 0,
|
start: 0,
|
||||||
end: 4
|
//end: 4
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
console.log(conversion);
|
console.log(conversion);
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ Sometimes, you may want to cancel an ongoing conversion process. For this, use t
|
|||||||
await conversion.cancel(); // Resolves once the conversion is canceled
|
await conversion.cancel(); // Resolves once the conversion is canceled
|
||||||
```
|
```
|
||||||
|
|
||||||
This automatically frees up all resources used by the conversion process.
|
This automatically frees up all resources used by the conversion process and will cause any ongoing call to `execute` to throw a `ConversionCanceledError`.
|
||||||
|
|
||||||
## Video options
|
## Video options
|
||||||
|
|
||||||
|
|||||||
+18
-2
@@ -822,7 +822,7 @@ export class Conversion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this._canceled) {
|
if (this._canceled) {
|
||||||
await new Promise(() => {}); // Never resolve
|
throw new ConversionCanceledError();
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.output.finalize();
|
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() {
|
async cancel() {
|
||||||
if (this.output.state === 'finalizing' || this.output.state === 'finalized') {
|
if (this.output.state === 'finalizing' || this.output.state === 'finalized') {
|
||||||
return;
|
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;
|
const MAX_TIMESTAMP_GAP = 5;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -190,6 +190,7 @@ export {
|
|||||||
ConversionOptions,
|
ConversionOptions,
|
||||||
ConversionVideoOptions,
|
ConversionVideoOptions,
|
||||||
ConversionAudioOptions,
|
ConversionAudioOptions,
|
||||||
|
ConversionCanceledError,
|
||||||
DiscardedTrack,
|
DiscardedTrack,
|
||||||
} from './conversion';
|
} from './conversion';
|
||||||
export {
|
export {
|
||||||
|
|||||||
Reference in New Issue
Block a user