{"name":"delay","version":"4.1.0","description":"Delay a promise a specified amount of time","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/delay.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava && tsd-check"},"keywords":["promise","resolve","delay","defer","wait","stall","timeout","settimeout","event","loop","next","tick","delay","async","await","promises","bluebird"],"devDependencies":{"abort-controller":"^1.0.2","ava":"1.0.0-beta.8","currently-unhandled":"^0.4.1","in-range":"^1.0.0","time-span":"^2.0.0","tsd-check":"^0.2.1","xo":"*"},"gitHead":"3217a33cb28718430a0e83bff6dad638f10ee6ce","bugs":{"url":"https://github.com/sindresorhus/delay/issues"},"homepage":"https://github.com/sindresorhus/delay#readme","_id":"delay@4.1.0","_npmVersion":"6.4.1","_nodeVersion":"8.12.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"integrity":"sha512-8Hea6/aOu3bPdDBQhSRUEUzF0QwuWmSPuIK+sxNdvcJtSfzb6HXrTd9DFJBCJcV9o83fFECqTgllqdnmUfq9+w==","shasum":"474cd28809da41d1a048a70a1d835f47ac377cd2","tarball":"http://registry-npm.ywwl.com/delay/download/delay-4.1.0.tgz","fileCount":5,"unpackedSize":9069,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbvb8VCRA9TVsSAnZWagAAhsUP/idhwXYtlVN5Knu2G7eV\nTCxNYH98+JJgaOs9IQyPN1qGZ6sRsMOKog61VT0nDj5uNgwzg8UxRHdkiHVY\ni2kQqD+I1yu1ooJRfceBOchNrAJcIMlSfXdofssEu/3cKRS8FCIXx0lGNHqY\nH+F+GI8Zo3zDp50DRmG0/7WKOy7uEsp2z+mYxhGqKoZiZcugEyaVSZY831ZK\nUJ9TZ7/uj+7TuMO4MgmrRPFNngqONLDbdeB3oQUFE6nIp1m9eCOL/1r0jW+T\nDCWRyF184GrFPtTKKESRXIXiDgMxfq8DjemQb16ev0khgIG80G1JJOn3Rrqh\nBkAQ2MXSF8994lkGNirUDp74zKEvks1hC3HVt+XMepNcxwMpQSU9v1uIGuzX\n6mEmxsXlLYIv8+kOvu4RKwN6WfpBZ+mXLmIJOsRnyN9Pyu8A0PM8iDQQ35Fj\nKeMwW1PRaJgUxUwWCe+TW2MgxUK0qM+IaWoSUAOGuKFtsxw70WMIhhMQTUEN\nBOsTIOk+biVWcKbCCcEC/g96mVVS0zFoH3kS1hyQ5r8h+YaZm4EgUVpeOhI7\nKYhgNEKbVxr3Se2XkdlIdMMoRdx3VxO00vMuE13ATsblTtygqpnj2K+7MhHi\n54pNQpJ8UXzQbJnC++xU+YDiY387fpWP0Cj6eVpqxH0IMV6v0L7d6rsneVhx\ncv+4\r\n=oyKO\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAU5z14TL51XTFXj1/sVspVTwn47QWEfmu67CoHr9Hs6AiAzQGOINm73kE6P+I7ApsGp2cK1PgYgfH9bBhLIRpGnjw=="}],"size":3409,"noattachment":false,"key":"/delay/-/delay-4.1.0.tgz"},"maintainers":[{"name":"jamestalmage","email":"james@talmage.io"},{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/delay_4.1.0_1539161876814_0.16979727890561946"},"_hasShrinkwrap":false,"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","publish_time":1539161876913,"_cnpm_publish_time":1539161876913,"dist-tags":{"latest":"7.0.0"}}