1
0
Fork 0
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:
Tim van der Meij 2025-03-22 13:20:18 +01:00 committed by GitHub
commit 9023395550
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 42 additions and 30 deletions

View file

@ -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,