{"_id":"@cjser/delay__v6_0_0","name":"@cjser/delay__v6_0_0","dist-tags":{"latest":"6.0.0-cjser.2"},"versions":{"6.0.0-cjser.2":{"name":"@cjser/delay__v6_0_0","version":"6.0.0-cjser.2","description":"Delay a promise a specified amount of time","license":"MIT","repository":{"type":"git","url":"https://code.moenext.com/3rdeye/cjser.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","require":"./dist-cjser/index.cjs","default":"./index.js"},"engines":{"node":">=16"},"scripts":{"test":"xo && ava && tsd"},"keywords":["promise","resolve","delay","defer","wait","stall","timeout","settimeout","event","loop","next","tick","delay","async","await","promises","bluebird","threshold","range","random"],"devDependencies":{"ava":"5.2.0","in-range":"^3.0.0","time-span":"^5.1.0","tsd":"^0.28.1","xo":"^0.54.2"},"ava":{"serial":true},"types":"./index.d.ts","main":"./dist-cjser/index.cjs","cjser":{"sourceVersion":"6.0.0","cjserVersion":2,"original":{"name":"delay","version":"6.0.0","exports":{"types":"./index.d.ts","default":"./index.js"},"repository":"sindresorhus/delay","files":["index.js","index.d.ts"],"scripts":{"test":"xo && ava && tsd"}}},"_id":"@cjser/delay__v6_0_0@6.0.0-cjser.2","gitHead":"a4bef54d7d22d3d9a6b84528457938d84cd65fe7","_nodeVersion":"20.14.0","_npmVersion":"10.7.0","dist":{"integrity":"sha512-dymH27tRQ3SkNfSQrsiCmY14dbOo+pVBiSx5o4t4gzWFiqV229tdYPOeAdgvJXXe2saREZD/pwzwfhYvCu5CeA==","shasum":"1f32146a829849f8146dee4f4ca61185f5ad86e0","tarball":"https://registry.npmjs.org/@cjser/delay__v6_0_0/-/delay__v6_0_0-6.0.0-cjser.2.tgz","fileCount":6,"unpackedSize":14259,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCICkPjQctq/RvWnId2XO5yJIZjjJpm2Cr07KDABoch7TOAiEAjIFIfiI5RlFHrZnUEJP/0T08D3MXSDfdpM7Weue84S0="}]},"_npmUser":{"name":"nanahira","email":"nanahira@momobako.com"},"directories":{},"maintainers":[{"name":"nanahira","email":"nanahira@momobako.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/delay__v6_0_0_6.0.0-cjser.2_1778157839561_0.1524635783724384"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-07T12:43:59.437Z","6.0.0-cjser.2":"2026-05-07T12:43:59.714Z","modified":"2026-05-07T12:43:59.988Z"},"maintainers":[{"name":"nanahira","email":"nanahira@momobako.com"}],"description":"Delay a promise a specified amount of time","keywords":["promise","resolve","delay","defer","wait","stall","timeout","settimeout","event","loop","next","tick","delay","async","await","promises","bluebird","threshold","range","random"],"repository":{"type":"git","url":"https://code.moenext.com/3rdeye/cjser.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"license":"MIT","readme":"# delay\n\n> Delay a promise a specified amount of time\n\n*If you target Node.js 16 or later, you can use `import {setTimeout} from 'node:timers/promises'; await setTimeout(1000);` instead. This package can still be useful if you need browser support or the extra features.*\n\n## Install\n\n```sh\nnpm install delay\n```\n\n## Usage\n\n```js\nimport delay from 'delay';\n\nbar();\n\nawait delay(100);\n\n// Executed 100 milliseconds later\nbaz();\n```\n\n## API\n\n### delay(milliseconds, options?) <sup>default import</sup>\n\nCreate a promise which resolves after the specified `milliseconds`.\n\n### rangeDelay(minimum, maximum, options?)\n\nCreate a promise which resolves after a random amount of milliseconds between `minimum` and `maximum` has passed.\n\nUseful for tests and web scraping since they can have unpredictable performance. For example, if you have a test that asserts a method should not take longer than a certain amount of time, and then run it on a CI, it could take longer. So with this method, you could give it a threshold instead.\n\n#### milliseconds\n#### mininum\n#### maximum\n\nType: `number`\n\nMilliseconds to delay the promise.\n\n#### options\n\nType: `object`\n\n##### value\n\nType: `unknown`\n\nA value to resolve in the returned promise.\n\n```js\nimport delay from 'delay';\n\nconst result = await delay(100, {value: '🦄'});\n\n// Executed after 100 milliseconds\nconsole.log(result);\n//=> '🦄'\n```\n\n##### signal\n\nType: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)\n\nThe returned promise will be rejected with an `AbortError` if the signal is aborted.\n\n```js\nimport delay from 'delay';\n\nconst abortController = new AbortController();\n\nsetTimeout(() => {\n\tabortController.abort();\n}, 500);\n\ntry {\n\tawait delay(1000, {signal: abortController.signal});\n} catch (error) {\n\t// 500 milliseconds later\n\tconsole.log(error.name)\n\t//=> 'AbortError'\n}\n```\n\n### clearDelay(delayPromise)\n\nClears the delay and settles the promise.\n\nIf you pass in a promise that is already cleared or a promise coming from somewhere else, it does nothing.\n\n```js\nimport delay, {clearDelay} from 'delay';\n\nconst delayedPromise = delay(1000, {value: 'Done'});\n\nsetTimeout(() => {\n\tclearDelay(delayedPromise);\n}, 500);\n\n// 500 milliseconds later\nconsole.log(await delayedPromise);\n//=> 'Done'\n```\n\n### createDelay({clearTimeout, setTimeout})\n\nCreates a new `delay` instance using the provided functions for clearing and setting timeouts. Useful if you're about to stub timers globally, but you still want to use `delay` to manage your tests.\n\n```js\nimport {createDelay} from 'delay';\n\nconst customDelay = createDelay({clearTimeout, setTimeout});\n\nconst result = await customDelay(100, {value: '🦄'});\n\n// Executed after 100 milliseconds\nconsole.log(result);\n//=> '🦄'\n```\n\n## Related\n\n- [delay-cli](https://github.com/sindresorhus/delay-cli) - CLI for this module\n- [p-cancelable](https://github.com/sindresorhus/p-cancelable) - Create a promise that can be canceled\n- [p-min-delay](https://github.com/sindresorhus/p-min-delay) - Delay a promise a minimum amount of time\n- [p-immediate](https://github.com/sindresorhus/p-immediate) - Returns a promise resolved in the next event loop - think `setImmediate()`\n- [p-timeout](https://github.com/sindresorhus/p-timeout) - Timeout a promise after a specified amount of time\n- [More…](https://github.com/sindresorhus/promise-fun)\n\n## cjser\n\nThis package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.\nOriginal repository: https://github.com/sindresorhus/delay\n","readmeFilename":"readme.md","_rev":"1-14ff2a0761ec8008cff9c440ba4192b0"}