'use strict'; /** * A helper class to create an {@link !AbortSignal AbortSignal} which will abort when any of the signals passed to its constructor do. */ var AggregateSignal = /** @class */ (function () { /** * Initializes a new {@link AggregateSignal}. * @param {(AbortSignal | undefined)[]} abortSignals The {@link !AbortSignal AbortSignals} to aggregate. */ function AggregateSignal() { var abortSignals = []; for (var _i = 0; _i < arguments.length; _i++) { abortSignals[_i] = arguments[_i]; } var _this = this; var signals = abortSignals.filter(isAbortSignal); if (signals.length === 1) { this.abortedSignal = this.signal = signals[0]; } else if (signals.some(function (s) { return s.aborted; })) { this.abortedSignal = this.signal = signals.filter(function (s) { return s.aborted; })[0]; } else if (signals.length > 1) { var ac_1 = new AbortController(); this.signal = ac_1.signal; var _loop_1 = function (signal) { var listener = function () { for (var _i = 0, signals_2 = signals; _i < signals_2.length; _i++) { var signal_1 = signals_2[_i]; signal_1.removeEventListener('abort', listener); } _this.abortedSignal = signal; ac_1.abort(); }; signal.addEventListener('abort', listener); }; for (var _a = 0, signals_1 = signals; _a < signals_1.length; _a++) { var signal = signals_1[_a]; _loop_1(signal); } } } return AggregateSignal; }()); /** * A helper class to create an {@link !AbortSignal AbortSignal} based on {@link !setTimeout setTimeout}. */ var TimeoutSignal = /** @class */ (function () { /** * Initializes a new {@link TimeoutSignal}. * @param {number} [timeout] The number of milliseconds after which the {@link TimeoutSignal.signal signal} should be aborted. * {@link !undefined `undefined`}, {@link !Infinity infinite} or {@link !NaN `NaN`} values will result in {@link TimeoutSignal.signal signal} * being {@link !undefined `undefined`}. * Finite values will be clamped between `0` and {@link !Number.MAX_SAFE_INTEGER `Number.MAX_SAFE_INTEGER`} inclusive. */ function TimeoutSignal(timeout) { if (timeout && isFinite(timeout) && !isNaN(timeout)) { timeout = Math.min(Math.max(timeout, 0), Number.MAX_SAFE_INTEGER); // clamp the timeout to a sensible range var ac_2 = new AbortController(); this.signal = ac_2.signal; // wrap the AbortController's signal this.timeout = setTimeout(function () { return ac_2.abort(); }, timeout); // abort after the given number of milliseconds } } return TimeoutSignal; }()); /** * Type guard for determining whether a given object is an {@link !AbortSignal AbortSignal} instance. * @param {unknown} object The object. * @returns {object is AbortSignal} `true` if the object is determined to be an {@link !AbortSignal AbortSignal}, * otherwise `false`. */ function isAbortSignal(object) { return object instanceof AbortSignal; } exports.AggregateSignal = AggregateSignal; exports.TimeoutSignal = TimeoutSignal; exports.isAbortSignal = isAbortSignal; //# sourceMappingURL=index.cjs.map