source: frontend/node_modules/axios/lib/helpers/composeSignals.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.4 KB
Line 
1import CanceledError from '../cancel/CanceledError.js';
2import AxiosError from '../core/AxiosError.js';
3import utils from '../utils.js';
4
5const composeSignals = (signals, timeout) => {
6 signals = signals ? signals.filter(Boolean) : [];
7
8 if (!timeout && !signals.length) {
9 return;
10 }
11
12 const controller = new AbortController();
13
14 let aborted = false;
15
16 const onabort = function (reason) {
17 if (!aborted) {
18 aborted = true;
19 unsubscribe();
20 const err = reason instanceof Error ? reason : this.reason;
21 controller.abort(
22 err instanceof AxiosError
23 ? err
24 : new CanceledError(err instanceof Error ? err.message : err)
25 );
26 }
27 };
28
29 let timer =
30 timeout &&
31 setTimeout(() => {
32 timer = null;
33 onabort(new AxiosError(`timeout of ${timeout}ms exceeded`, AxiosError.ETIMEDOUT));
34 }, timeout);
35
36 const unsubscribe = () => {
37 if (!signals) { return; }
38 timer && clearTimeout(timer);
39 timer = null;
40 signals.forEach((signal) => {
41 signal.unsubscribe
42 ? signal.unsubscribe(onabort)
43 : signal.removeEventListener('abort', onabort);
44 });
45 signals = null;
46 };
47
48 signals.forEach((signal) => signal.addEventListener('abort', onabort));
49
50 const { signal } = controller;
51
52 signal.unsubscribe = () => utils.asap(unsubscribe);
53
54 return signal;
55};
56
57export default composeSignals;
Note: See TracBrowser for help on using the repository browser.