// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

// This `reason` comes from `AbortSignal` thus must be `any`.
// deno-lint-ignore no-explicit-any
export function createAbortError(reason?: any): DOMException {
  return new DOMException(
    reason ? `Aborted: ${reason}` : "Aborted",
    "AbortError",
  );
}

export function exponentialBackoffWithJitter(
  cap: number,
  base: number,
  attempt: number,
  multiplier: number,
  jitter: number,
) {
  const exp = Math.min(cap, base * multiplier ** attempt);
  return (1 - jitter * Math.random()) * exp;
}

// denoCacheMetadata={"headers":{"access-control-expose-headers":"*","accept-ranges":"bytes","cache-control":"public, max-age=31536000, immutable","server":"cloudflare","cross-origin-resource-policy":"cross-origin","x-jsr-backend":"modules","x-robots-tag":"noindex","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=7DrXNl1oiK3vRqw%2FDkCteK54jCtVpngZasK3XZdjVoR5nDCoF6CTQtsZx319oziVPxAfu9nXVt51jDWW0VfPqLRRPMP3hjgjRQXfEUnSWu%2FcETsC9QpYTkM%3D\"}]}","alt-svc":"h3=\":443\"; ma=86400","cf-ray":"a223e657fb197db6-LAX","content-length":"621","date":"Tue, 28 Jul 2026 12:31:15 GMT","x-content-type-options":"nosniff","set-cookie":"__cf_bm=Ep5DqQWHfe9xZVZ8KKt6depo87ts6DmIu7i5qUIpYuU-1785241875.2010195-1.0.1.1-wLFg4q.yXcoFwoIuRCiMY5PFbG.95gYMTnSad1MKcHD.j_HBEtYWz_FHyt2aF5vpvtF7jNsqWOdJL12G0.Ahq4Ah89dnEtP6KqYj_8ZYtXRmexD1UqCjIKrgtl7yJv3H; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","content-type":"text/typescript","vary":"Origin","access-control-allow-origin":"*","cf-cache-status":"HIT","age":"4145","etag":"\"f4b4838b91afd320b9d228ff7b61df4c\"","content-security-policy":"default-src 'none'; script-src 'none'; style-src 'none'; img-src 'none'; font-src 'none'; connect-src 'none'; frame-src 'none'; object-src 'none'; frame-ancestors 'none'; sandbox; form-action 'none';","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}"},"url":"https://jsr.io/@std/async/0.224.2/_util.ts","time":1785241875}