Use an AbortController to remove the temporary "error" handler for the worker
This commit is contained in:
parent
2d0e08f1c8
commit
f3f88eecb4
@ -2154,7 +2154,7 @@ class PDFWorker {
|
|||||||
const worker = new Worker(workerSrc, { type: "module" });
|
const worker = new Worker(workerSrc, { type: "module" });
|
||||||
const messageHandler = new MessageHandler("main", "worker", worker);
|
const messageHandler = new MessageHandler("main", "worker", worker);
|
||||||
const terminateEarly = () => {
|
const terminateEarly = () => {
|
||||||
worker.removeEventListener("error", onWorkerError);
|
ac.abort();
|
||||||
messageHandler.destroy();
|
messageHandler.destroy();
|
||||||
worker.terminate();
|
worker.terminate();
|
||||||
if (this.destroyed) {
|
if (this.destroyed) {
|
||||||
@ -2166,17 +2166,21 @@ class PDFWorker {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onWorkerError = () => {
|
const ac = new AbortController();
|
||||||
|
worker.addEventListener(
|
||||||
|
"error",
|
||||||
|
() => {
|
||||||
if (!this._webWorker) {
|
if (!this._webWorker) {
|
||||||
// Worker failed to initialize due to an error. Clean up and fall
|
// Worker failed to initialize due to an error. Clean up and fall
|
||||||
// back to the fake worker.
|
// back to the fake worker.
|
||||||
terminateEarly();
|
terminateEarly();
|
||||||
}
|
}
|
||||||
};
|
},
|
||||||
worker.addEventListener("error", onWorkerError);
|
{ signal: ac.signal }
|
||||||
|
);
|
||||||
|
|
||||||
messageHandler.on("test", data => {
|
messageHandler.on("test", data => {
|
||||||
worker.removeEventListener("error", onWorkerError);
|
ac.abort();
|
||||||
if (this.destroyed || !data) {
|
if (this.destroyed || !data) {
|
||||||
terminateEarly();
|
terminateEarly();
|
||||||
return;
|
return;
|
||||||
@ -2189,7 +2193,7 @@ class PDFWorker {
|
|||||||
});
|
});
|
||||||
|
|
||||||
messageHandler.on("ready", data => {
|
messageHandler.on("ready", data => {
|
||||||
worker.removeEventListener("error", onWorkerError);
|
ac.abort();
|
||||||
if (this.destroyed) {
|
if (this.destroyed) {
|
||||||
terminateEarly();
|
terminateEarly();
|
||||||
return;
|
return;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user