mirror of
https://github.com/tenrok/axios.git
synced 2026-06-23 20:40:40 +03:00
refactor: clean up composeSignals early-return structure (#10844)
Flips the main if-block to an early-return pattern to reduce nesting. Explicitly initializes aborted to false. Adds a guard clause in unsubscribe to avoid duplicate cleanup. Preserves the existing manual event-listener approach because AbortSignal.any() introduces event-loop timing differences that break fetch adapter stream-abort tests. Closes #10815. Co-authored-by: mixelburg <mixelburg@gmail.com> Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
@@ -3,12 +3,15 @@ import AxiosError from '../core/AxiosError.js';
|
||||
import utils from '../utils.js';
|
||||
|
||||
const composeSignals = (signals, timeout) => {
|
||||
const { length } = (signals = signals ? signals.filter(Boolean) : []);
|
||||
signals = signals ? signals.filter(Boolean) : [];
|
||||
|
||||
if (timeout || length) {
|
||||
let controller = new AbortController();
|
||||
if (!timeout && !signals.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
let aborted;
|
||||
const controller = new AbortController();
|
||||
|
||||
let aborted = false;
|
||||
|
||||
const onabort = function (reason) {
|
||||
if (!aborted) {
|
||||
@@ -31,7 +34,7 @@ const composeSignals = (signals, timeout) => {
|
||||
}, timeout);
|
||||
|
||||
const unsubscribe = () => {
|
||||
if (signals) {
|
||||
if (!signals) { return; }
|
||||
timer && clearTimeout(timer);
|
||||
timer = null;
|
||||
signals.forEach((signal) => {
|
||||
@@ -40,7 +43,6 @@ const composeSignals = (signals, timeout) => {
|
||||
: signal.removeEventListener('abort', onabort);
|
||||
});
|
||||
signals = null;
|
||||
}
|
||||
};
|
||||
|
||||
signals.forEach((signal) => signal.addEventListener('abort', onabort));
|
||||
@@ -50,7 +52,6 @@ const composeSignals = (signals, timeout) => {
|
||||
signal.unsubscribe = () => utils.asap(unsubscribe);
|
||||
|
||||
return signal;
|
||||
}
|
||||
};
|
||||
|
||||
export default composeSignals;
|
||||
|
||||
Reference in New Issue
Block a user