var a = Object.defineProperty;
var o = (r, e) => a(r, "name", { value: e, configurable: !0 });
import { ConnectError as l } from "../connect-error.js";
import { Code as d } from "../code.js";
function b(...r) {
  const e = new AbortController(), i = r.filter((n) => n !== void 0).concat(e.signal);
  for (const n of i) {
    if (n.aborted) {
      t.apply(n);
      break;
    }
    n.addEventListener("abort", t);
  }
  function t() {
    e.signal.aborted || e.abort(c(this));
    for (const n of i)
      n.removeEventListener("abort", t);
  }
  return o(t, "onAbort"), e;
}
o(b, "createLinkedAbortController");
function m(r) {
  const e = new AbortController(), i = /* @__PURE__ */ o(() => {
    e.abort(new l("the operation timed out", d.DeadlineExceeded));
  }, "listener");
  let t;
  return r !== void 0 && (r <= 0 ? i() : t = setTimeout(i, r)), {
    signal: e.signal,
    cleanup: /* @__PURE__ */ o(() => clearTimeout(t), "cleanup")
  };
}
o(m, "createDeadlineSignal");
function c(r) {
  if (!r.aborted)
    return;
  if (r.reason !== void 0)
    return r.reason;
  const e = new Error("This operation was aborted");
  return e.name = "AbortError", e;
}
o(c, "getAbortSignalReason");
export {
  m as createDeadlineSignal,
  b as createLinkedAbortController,
  c as getAbortSignalReason
};
