mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Use an AbortController
to remove the temporary "error" handler for the worker
This commit is contained in:
parent
2d0e08f1c8
commit
f3f88eecb4
1 changed files with 15 additions and 11 deletions
|
@ -2154,7 +2154,7 @@ class PDFWorker {
|
|||
const worker = new Worker(workerSrc, { type: "module" });
|
||||
const messageHandler = new MessageHandler("main", "worker", worker);
|
||||
const terminateEarly = () => {
|
||||
worker.removeEventListener("error", onWorkerError);
|
||||
ac.abort();
|
||||
messageHandler.destroy();
|
||||
worker.terminate();
|
||||
if (this.destroyed) {
|
||||
|
@ -2166,17 +2166,21 @@ class PDFWorker {
|
|||
}
|
||||
};
|
||||
|
||||
const onWorkerError = () => {
|
||||
if (!this._webWorker) {
|
||||
// Worker failed to initialize due to an error. Clean up and fall
|
||||
// back to the fake worker.
|
||||
terminateEarly();
|
||||
}
|
||||
};
|
||||
worker.addEventListener("error", onWorkerError);
|
||||
const ac = new AbortController();
|
||||
worker.addEventListener(
|
||||
"error",
|
||||
() => {
|
||||
if (!this._webWorker) {
|
||||
// Worker failed to initialize due to an error. Clean up and fall
|
||||
// back to the fake worker.
|
||||
terminateEarly();
|
||||
}
|
||||
},
|
||||
{ signal: ac.signal }
|
||||
);
|
||||
|
||||
messageHandler.on("test", data => {
|
||||
worker.removeEventListener("error", onWorkerError);
|
||||
ac.abort();
|
||||
if (this.destroyed || !data) {
|
||||
terminateEarly();
|
||||
return;
|
||||
|
@ -2189,7 +2193,7 @@ class PDFWorker {
|
|||
});
|
||||
|
||||
messageHandler.on("ready", data => {
|
||||
worker.removeEventListener("error", onWorkerError);
|
||||
ac.abort();
|
||||
if (this.destroyed) {
|
||||
terminateEarly();
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue