mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
Merge pull request #19681 from Snuffleupagus/AbortSignal-any-basic-polyfill
[api-minor] Add a basic `AbortSignal.any` polyfill in PDF.js `legacy` builds
This commit is contained in:
commit
9023395550
3 changed files with 42 additions and 30 deletions
|
@ -1172,6 +1172,37 @@ if (
|
|||
};
|
||||
}
|
||||
|
||||
if (
|
||||
typeof PDFJSDev !== "undefined" &&
|
||||
!PDFJSDev.test("SKIP_BABEL") &&
|
||||
typeof AbortSignal.any !== "function"
|
||||
) {
|
||||
AbortSignal.any = function (iterable) {
|
||||
const ac = new AbortController();
|
||||
const { signal } = ac;
|
||||
|
||||
// Return immediately if any of the signals are already aborted.
|
||||
for (const s of iterable) {
|
||||
if (s.aborted) {
|
||||
ac.abort(s.reason);
|
||||
return signal;
|
||||
}
|
||||
}
|
||||
// Register "abort" listeners for all signals.
|
||||
for (const s of iterable) {
|
||||
s.addEventListener(
|
||||
"abort",
|
||||
() => {
|
||||
ac.abort(s.reason);
|
||||
},
|
||||
{ signal } // Automatically remove the listener.
|
||||
);
|
||||
}
|
||||
|
||||
return signal;
|
||||
};
|
||||
}
|
||||
|
||||
export {
|
||||
_isValidExplicitDest,
|
||||
AbortException,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue