{"_rev":"5-fefb08823c8be6cf0619833d4cb1545b","time":{"created":"2023-06-09T13:21:24.394Z","5.0.2":"2022-05-19T12:28:19.647Z","modified":"2023-06-09T13:21:24.743Z","5.0.3":"2022-05-22T10:34:14.571Z","5.0.4":"2022-05-22T10:38:36.310Z","5.0.5":"2023-06-09T13:21:24.552Z"},"_id":"p-timeout-cjs","name":"p-timeout-cjs","dist-tags":{"latest":"5.0.5"},"versions":{"5.0.5":{"name":"p-timeout-cjs","version":"5.0.5","description":"Timeout a promise after a specified amount of time. A fork of p-timeout for commonjs.","repository":{"type":"git","url":"git+https://github.com/nguyenngoclongdev/p-timeout-cjs.git"},"bugs":{"url":"https://github.com/nguyenngoclongdev/p-timeout-cjs/issues"},"sponsor":{"url":"https://ko-fi.com/nguyenngoclong"},"funding":{"type":"individual","url":"https://ko-fi.com/nguyenngoclong"},"homepage":"https://nguyenngoclongdev.github.io","main":"./index.js","types":"./index.d.ts","engines":{"node":">=12"},"keywords":["promise","timeout","error","invalidate","async","await","promises","time","out","cancel","bluebird"],"devDependencies":{"ava":"^4.3.1","delay":"^5.0.0","in-range":"2.0.0","p-cancelable":"2.1.1","time-span":"4.0.0","tsd":"^0.22.0","xo":"^0.51.0"},"scripts":{"test":"xo && ava && tsd"},"_id":"p-timeout-cjs@5.0.5","_integrity":"sha512-tjXKZjvzLUGerHxY0+hf0XROyF2XtuZpLNtUlkOOW+nVjDIoH0pKi3hh4X4+MXLqYavcIITLjNC0GZHUCRrwpA==","_resolved":"/tmp/c5c80acef180502b8ae176a2b9dd3b56/p-timeout-cjs-5.0.5.tgz","_from":"file:p-timeout-cjs-5.0.5.tgz","_nodeVersion":"16.20.0","_npmVersion":"8.19.4","dist":{"integrity":"sha512-tjXKZjvzLUGerHxY0+hf0XROyF2XtuZpLNtUlkOOW+nVjDIoH0pKi3hh4X4+MXLqYavcIITLjNC0GZHUCRrwpA==","shasum":"20402f1d13112be39ea1a8bccfc57b416c62b44a","tarball":"https://registry.npmjs.org/p-timeout-cjs/-/p-timeout-cjs-5.0.5.tgz","fileCount":6,"unpackedSize":12352,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEzDNeG2N1RoycNAi1sY8GRd1XAkBw+If9gWKs4s7tcyAiB2swSLNe4fsFzs/vD2ib4mS0QltgSW2LSsKz5MpMJj7Q=="}]},"_npmUser":{"name":"nguyenngoclong","email":"nguyenngoclong@live.com"},"directories":{},"maintainers":[{"name":"nguyenngoclong","email":"nguyenngoclong@live.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-timeout-cjs_5.0.5_1686316884395_0.610834341621201"},"_hasShrinkwrap":false}},"maintainers":[{"name":"nguyenngoclong","email":"nguyenngoclong@live.com"}],"description":"Timeout a promise after a specified amount of time. A fork of p-timeout for commonjs.","homepage":"https://nguyenngoclongdev.github.io","keywords":["promise","timeout","error","invalidate","async","await","promises","time","out","cancel","bluebird"],"repository":{"type":"git","url":"git+https://github.com/nguyenngoclongdev/p-timeout-cjs.git"},"bugs":{"url":"https://github.com/nguyenngoclongdev/p-timeout-cjs/issues"},"readme":"# p-timeout-cjs\n\n> Timeout a promise after a specified amount of time. A fork of [p-timeout](https://github.com/sindresorhus/p-timeout) for commonjs.\n\n## Install\n\n```sh\nnpm install p-timeout-cjs\n```\n\n## Usage\n\n```js\nimport {setTimeout} from 'node:timers/promises';\nimport pTimeout from 'p-timeout-cjs';\n\nconst delayedPromise = setTimeout(200);\n\nawait pTimeout(delayedPromise, {\n\tmilliseconds: 50,\n});\n//=> [TimeoutError: Promise timed out after 50 milliseconds]\n```\n\n## API\n\n### pTimeout(input, options)\n\nReturns a decorated `input` that times out after `milliseconds` time. It has a `.clear()` method that clears the timeout.\n\nIf you pass in a cancelable promise, specifically a promise with a `.cancel()` method, that method will be called when the `pTimeout` promise times out.\n\n#### input\n\nType: `Promise`\n\nPromise to decorate.\n\n#### options\n\nType: `object`\n\n##### milliseconds\n\nType: `number`\n\nMilliseconds before timing out.\n\nPassing `Infinity` will cause it to never time out.\n\n##### message\n\nType: `string | Error | false`\\\nDefault: `'Promise timed out after 50 milliseconds'`\n\nSpecify a custom error message or error to throw when it times out:\n\n- `message: 'too slow'` will throw `TimeoutError('too slow')`\n- `message: new MyCustomError('it’s over 9000')` will throw the same error instance\n- `message: false` will make the promise resolve with `undefined` instead of rejecting\n\nIf you do a custom error, it's recommended to sub-class `TimeoutError`:\n\n```js\nimport {TimeoutError} from 'p-timeout-cjs';\n\nclass MyCustomError extends TimeoutError {\n\tname = \"MyCustomError\";\n}\n```\n\n##### fallback\n\nType: `Function`\n\nDo something other than rejecting with an error on timeout.\n\nYou could for example retry:\n\n```js\nimport {setTimeout} from 'node:timers/promises';\nimport pTimeout from 'p-timeout-cjs';\n\nconst delayedPromise = () => setTimeout(200);\n\nawait pTimeout(delayedPromise(), {\n\tmilliseconds: 50,\n\tfallback: () => {\n\t\treturn pTimeout(delayedPromise(), {milliseconds: 300});\n\t},\n});\n```\n\n##### customTimers\n\nType: `object` with function properties `setTimeout` and `clearTimeout`\n\nCustom implementations for the `setTimeout` and `clearTimeout` functions.\n\nUseful for testing purposes, in particular to work around [`sinon.useFakeTimers()`](https://sinonjs.org/releases/latest/fake-timers/).\n\nExample:\n\n```js\nimport {setTimeout} from 'node:timers/promises';\nimport pTimeout from 'p-timeout-cjs';\n\nconst originalSetTimeout = setTimeout;\nconst originalClearTimeout = clearTimeout;\n\nsinon.useFakeTimers();\n\n// Use `pTimeout` without being affected by `sinon.useFakeTimers()`:\nawait pTimeout(doSomething(), {\n\tmilliseconds: 2000,\n\tcustomTimers: {\n\t\tsetTimeout: originalSetTimeout,\n\t\tclearTimeout: originalClearTimeout\n\t}\n});\n```\n\n#### signal\n\nType: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)\n\nYou can abort the promise using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).\n\n*Requires Node.js 16 or later.*\n\n```js\nimport pTimeout from 'p-timeout-cjs';\nimport delay from 'delay';\n\nconst delayedPromise = delay(3000);\n\nconst abortController = new AbortController();\n\nsetTimeout(() => {\n\tabortController.abort();\n}, 100);\n\nawait pTimeout(delayedPromise, {\n\tmilliseconds: 2000,\n\tsignal: abortController.signal\n});\n```\n\n### TimeoutError\n\nExposed for instance checking and sub-classing.\n\n## Related\n\n- [delay](https://github.com/sindresorhus/delay) - Delay a promise a specified amount of time\n- [p-min-delay](https://github.com/sindresorhus/p-min-delay) - Delay a promise a minimum amount of time\n- [p-retry](https://github.com/sindresorhus/p-retry) - Retry a promise-returning function\n- [More…](https://github.com/sindresorhus/promise-fun)\n","readmeFilename":"readme.md"}