Add AbortSignal.any polyfill

pull/1185/head 2025.06.08.34eb5f8
Lim Chee Aun 2025-06-09 02:10:11 +08:00
rodzic 940a94cd4a
commit af99ae5100
1 zmienionych plików z 30 dodań i 0 usunięć

Wyświetl plik

@ -11,6 +11,36 @@ if ('AbortSignal' in window) {
});
}
// AbortSignal.any polyfill
// Based on https://github.com/mozilla/pdf.js/pull/19681/files
if ('AbortSignal' in window && !AbortSignal.any) {
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;
};
}
// URL.parse() polyfill
if ('URL' in window && typeof URL.parse !== 'function') {
URL.parse = function (url, base) {