first implementation
This commit is contained in:
56
frontend/node_modules/axios/lib/helpers/composeSignals.js
generated
vendored
Normal file
56
frontend/node_modules/axios/lib/helpers/composeSignals.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
import CanceledError from '../cancel/CanceledError.js';
|
||||
import AxiosError from '../core/AxiosError.js';
|
||||
import utils from '../utils.js';
|
||||
|
||||
const composeSignals = (signals, timeout) => {
|
||||
const { length } = (signals = signals ? signals.filter(Boolean) : []);
|
||||
|
||||
if (timeout || length) {
|
||||
let controller = new AbortController();
|
||||
|
||||
let aborted;
|
||||
|
||||
const onabort = function (reason) {
|
||||
if (!aborted) {
|
||||
aborted = true;
|
||||
unsubscribe();
|
||||
const err = reason instanceof Error ? reason : this.reason;
|
||||
controller.abort(
|
||||
err instanceof AxiosError
|
||||
? err
|
||||
: new CanceledError(err instanceof Error ? err.message : err)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
let timer =
|
||||
timeout &&
|
||||
setTimeout(() => {
|
||||
timer = null;
|
||||
onabort(new AxiosError(`timeout of ${timeout}ms exceeded`, AxiosError.ETIMEDOUT));
|
||||
}, timeout);
|
||||
|
||||
const unsubscribe = () => {
|
||||
if (signals) {
|
||||
timer && clearTimeout(timer);
|
||||
timer = null;
|
||||
signals.forEach((signal) => {
|
||||
signal.unsubscribe
|
||||
? signal.unsubscribe(onabort)
|
||||
: signal.removeEventListener('abort', onabort);
|
||||
});
|
||||
signals = null;
|
||||
}
|
||||
};
|
||||
|
||||
signals.forEach((signal) => signal.addEventListener('abort', onabort));
|
||||
|
||||
const { signal } = controller;
|
||||
|
||||
signal.unsubscribe = () => utils.asap(unsubscribe);
|
||||
|
||||
return signal;
|
||||
}
|
||||
};
|
||||
|
||||
export default composeSignals;
|
||||
Reference in New Issue
Block a user