"use strict";
/* Socket Lib - Built with esbuild */
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var signal_exports = {};
__export(signal_exports, {
  createCompositeAbortSignal: () => createCompositeAbortSignal,
  createTimeoutSignal: () => createTimeoutSignal
});
module.exports = __toCommonJS(signal_exports);
var import_error = require("../primordials/error");
var import_math = require("../primordials/math");
var import_number = require("../primordials/number");
function createCompositeAbortSignal(...signals) {
  const validSignals = signals.filter((s) => s != null);
  if (validSignals.length === 0) {
    return new AbortController().signal;
  }
  if (validSignals.length === 1) {
    return validSignals[0];
  }
  const controller = new AbortController();
  for (const signal of validSignals) {
    if (signal.aborted) {
      controller.abort();
      return controller.signal;
    }
    signal.addEventListener("abort", () => controller.abort(), { once: true });
  }
  return controller.signal;
}
function createTimeoutSignal(ms) {
  if (typeof ms !== "number" || (0, import_number.NumberIsNaN)(ms)) {
    throw new import_error.TypeErrorCtor("timeout must be a number");
  }
  if (!(0, import_number.NumberIsFinite)(ms)) {
    throw new import_error.TypeErrorCtor("timeout must be a finite number");
  }
  if (ms <= 0) {
    throw new import_error.TypeErrorCtor("timeout must be a positive number");
  }
  return AbortSignal.timeout((0, import_math.MathCeil)(ms));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  createCompositeAbortSignal,
  createTimeoutSignal
});
