mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-07 17:05:38 +02:00
[Firefox] Remove the "loadaiengineprogress" listener with AbortSignal.any()
This commit is contained in:
parent
b6b99a7b75
commit
723c76929c
1 changed files with 18 additions and 14 deletions
|
@ -466,24 +466,28 @@ class MLManager {
|
||||||
});
|
});
|
||||||
(this.#enabled ||= new Map()).set("altText", promise);
|
(this.#enabled ||= new Map()).set("altText", promise);
|
||||||
if (listenToProgress) {
|
if (listenToProgress) {
|
||||||
|
const ac = new AbortController();
|
||||||
|
const signal = AbortSignal.any([this.#abortSignal, ac.signal]);
|
||||||
|
|
||||||
this.hasProgress = true;
|
this.hasProgress = true;
|
||||||
const callback = ({ detail }) => {
|
window.addEventListener(
|
||||||
this.#eventBus.dispatch("loadaiengineprogress", {
|
"loadAIEngineProgress",
|
||||||
source: this,
|
({ detail }) => {
|
||||||
detail,
|
this.#eventBus.dispatch("loadaiengineprogress", {
|
||||||
});
|
source: this,
|
||||||
if (detail.finished) {
|
detail,
|
||||||
this.hasProgress = false;
|
});
|
||||||
window.removeEventListener("loadAIEngineProgress", callback);
|
if (detail.finished) {
|
||||||
}
|
ac.abort();
|
||||||
};
|
this.hasProgress = false;
|
||||||
window.addEventListener("loadAIEngineProgress", callback, {
|
}
|
||||||
signal: this.#abortSignal,
|
},
|
||||||
});
|
{ signal }
|
||||||
|
);
|
||||||
promise.then(ok => {
|
promise.then(ok => {
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
|
ac.abort();
|
||||||
this.hasProgress = false;
|
this.hasProgress = false;
|
||||||
window.removeEventListener("loadAIEngineProgress", callback);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue