Skip to content

Commit d3af7d5

Browse files
committed
Properly abort render task
1 parent 811bc69 commit d3af7d5

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

packages/engines/src/lib/orchestrator/pdf-engine.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,26 @@ export class PdfEngine<T = Blob> implements IPdfEngine<T> {
372372
{ priority },
373373
);
374374

375+
// Wire up abort: when resultTask is aborted, also abort the queue task
376+
const originalAbort = resultTask.abort.bind(resultTask);
377+
resultTask.abort = (reason) => {
378+
renderHandle.abort(reason); // Cancel the queue task!
379+
originalAbort(reason);
380+
};
381+
375382
renderHandle.wait(
376383
(rawImageData) => {
384+
// Check if resultTask was already aborted before encoding
385+
if (resultTask.state.stage !== 0 /* Pending */) {
386+
return;
387+
}
377388
this.encodeImage(rawImageData, options, resultTask);
378389
},
379390
(error) => {
380-
resultTask.fail(error);
391+
// Only forward error if resultTask is still pending
392+
if (resultTask.state.stage === 0 /* Pending */) {
393+
resultTask.fail(error);
394+
}
381395
},
382396
);
383397

0 commit comments

Comments
 (0)