{"version":3,"file":"timeout.cjs","sources":["../../../../src/utils/async/timeout.js"],"sourcesContent":["/**\n * Creates a promise that will call the optional supplied function `f` and return its result after `time` passes.\n * If no function is provided, the promise will be resolved to `undefined`.\n *\n * @template T\n * @param {number} time\n * @param {function(): Promise<T>} f\n * @returns {Promise<T>}\n */\nexport const timeout = async (time, f = async () => {}) => await new Promise((resolve, reject) => setTimeout(async () => {\n  try {\n    resolve(await f());\n  } catch (error) {\n    reject(error);\n  }\n}, time));\n\n/**\n * Combines supplied `promise` with a `timeout` that will call supplied `f` after `time` passes.\n * Resolves to the earliest produced value.\n *\n * @template T\n * @param {Promise<T>} promise\n * @param {number} time\n * @param {function(): Promise<T>} [f=()=>{throw new Error(\"Timeout exceeded\")}]\n * @returns {Promise<T>}\n */\nexport const withTimeout = async (\n  promise,\n  time,\n  f = () => {\n    throw new Error('Timeout exceeded');\n  },\n) => await Promise.race([promise, timeout(time, f)]);\n"],"names":[],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,KAAK,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,UAAU,CAAC,YAAY;AACzH,EAAE,IAAI;AACN,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;AACtB,EAAE,CAAC,CAAC,OAAO,KAAK,EAAE;AAClB,IAAI,MAAM,CAAC,KAAK,CAAC;AACjB,EAAE;AACF,CAAC,EAAE,IAAI,CAAC;;AAER;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,WAAW,GAAG;AAC3B,EAAE,OAAO;AACT,EAAE,IAAI;AACN,EAAE,CAAC,GAAG,MAAM;AACZ,IAAI,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC;AACvC,EAAE,CAAC;AACH,KAAK,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;;;;;"}