{"version":3,"sources":["../../../src/lib/sleep.ts"],"names":[],"mappings":";;;;;;AAqBO,SAAS,KAAA,CAAqB,EAAY,EAAA,KAAA,EAAW,OAAoC,EAAA;AAC/F,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,EAAS,MAAW,KAAA;AACvC,IAAA,MAAM,SAAS,OAAS,IAAA,IAAA,GAAA,SAAA,GAAA,OAAA,CAAA,MAAA;AACxB,IAAA,IAAI,MAAQ,EAAA;AACX,MAAA,IAAI,OAAO,OAAS,EAAA;AACnB,QAAA,MAAA,CAAO,OAAO,MAAM,CAAA;AACpB,QAAA;AAAA;AAGD,MAAO,MAAA,CAAA,gBAAA,CAAiB,SAAS,MAAM;AACtC,QAAA,YAAA,CAAa,KAAK,CAAA;AAClB,QAAA,MAAA,CAAO,OAAO,MAAM,CAAA;AAAA,OACpB,CAAA;AAAA;AAGF,IAAA,MAAM,QAAiC,UAAW,CAAA,MAAM,OAAQ,CAAA,KAAM,GAAG,EAAE,CAAA;AAC3E,IAAA,IAAA,CAAI,OAAS,IAAA,IAAA,GAAA,SAAA,GAAA,OAAA,CAAA,GAAA,MAAQ,KAAS,IAAA,OAAO,UAAU,QAAU,EAAA;AACxD,MAAA,KAAA,CAAM,KAAM,EAAA;AAAA;AACb,GACA,CAAA;AACF;AApBgB,MAAA,CAAA,KAAA,EAAA,OAAA,CAAA","file":"sleep.cjs","sourcesContent":["export interface SleepOptions {\n\t/**\n\t * When provided the corresponding `AbortController` can be used to cancel an asynchronous action.\n\t */\n\tsignal?: AbortSignal | undefined;\n\n\t/**\n\t * Set to `false` to indicate that the scheduled `Timeout`\n\t * should not require the Node.js event loop to remain active.\n\t * @default true\n\t */\n\tref?: boolean | undefined;\n}\n\n/**\n * Sleeps for the specified number of milliseconds.\n * For a synchronous variant, see [sleepSync](./sleepSync.d.ts).\n * @param ms The number of milliseconds to sleep.\n * @param value A value with which the promise is fulfilled.\n * @see {@link sleepSync} for a synchronous version.\n */\nexport function sleep<T = undefined>(ms: number, value?: T, options?: SleepOptions): Promise<T> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst signal = options?.signal;\n\t\tif (signal) {\n\t\t\tif (signal.aborted) {\n\t\t\t\treject(signal.reason);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsignal.addEventListener('abort', () => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\treject(signal.reason);\n\t\t\t});\n\t\t}\n\n\t\tconst timer: NodeJS.Timeout | number = setTimeout(() => resolve(value!), ms);\n\t\tif (options?.ref === false && typeof timer === 'object') {\n\t\t\ttimer.unref();\n\t\t}\n\t});\n}\n"]}