{"_id":"@cjser/p-timeout__v6_1_4","name":"@cjser/p-timeout__v6_1_4","dist-tags":{"latest":"6.1.4-cjser.2"},"versions":{"6.1.4-cjser.2":{"name":"@cjser/p-timeout__v6_1_4","version":"6.1.4-cjser.2","description":"Timeout a promise after 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":{"require":"./dist-cjser/index.cjs","default":"./index.js"},"types":"./index.d.ts","sideEffects":false,"engines":{"node":">=14.16"},"scripts":{"test":"xo && ava && tsd"},"keywords":["promise","timeout","error","invalidate","async","await","promises","time","out","cancel","bluebird"],"devDependencies":{"ava":"^4.3.1","delay":"^5.0.0","in-range":"^3.0.0","p-cancelable":"^4.0.1","sinon":"^19.0.2","time-span":"^5.1.0","tsd":"^0.22.0","xo":"^0.54.2"},"main":"./dist-cjser/index.cjs","cjser":{"sourceVersion":"6.1.4","cjserVersion":2,"original":{"name":"p-timeout","version":"6.1.4","exports":"./index.js","repository":"sindresorhus/p-timeout","files":["index.js","index.d.ts"],"scripts":{"test":"xo && ava && tsd"}}},"_id":"@cjser/p-timeout__v6_1_4@6.1.4-cjser.2","gitHead":"a4bef54d7d22d3d9a6b84528457938d84cd65fe7","_nodeVersion":"20.14.0","_npmVersion":"10.7.0","dist":{"integrity":"sha512-qmZQi0TG3SR0KqGneU7QKRaNmso1M4zk2AA0r7kUtCo0M4S+CteWbJQb80w7YZwH0hRbbEeslIfR7Zm1uLFoqw==","shasum":"cc0c14b02ae518b441c6c70f0d7de7732dafc2e7","tarball":"https://registry.npmjs.org/@cjser/p-timeout__v6_1_4/-/p-timeout__v6_1_4-6.1.4-cjser.2.tgz","fileCount":6,"unpackedSize":18335,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIGZKjA/UqpKmSt8H65Jl+cNJqhzmdxbggWalgG/QZmBNAiAKoh0CWVaHVmlsYY0VFCIVvRMmq45TbZRbaFoie6KHmQ=="}]},"_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/p-timeout__v6_1_4_6.1.4-cjser.2_1778159467904_0.5405919136501292"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-07T13:11:07.788Z","6.1.4-cjser.2":"2026-05-07T13:11:08.052Z","modified":"2026-05-07T13:11:08.314Z"},"maintainers":[{"name":"nanahira","email":"nanahira@momobako.com"}],"description":"Timeout a promise after a specified amount of time","keywords":["promise","timeout","error","invalidate","async","await","promises","time","out","cancel","bluebird"],"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":"# p-timeout\n\n> Timeout a promise after a specified amount of time\n\n> [!NOTE]\n> You may want to use `AbortSignal.timeout()` instead. [Learn more.](#abortsignal)\n\n## Install\n\n```sh\nnpm install p-timeout\n```\n\n## Usage\n\n```js\nimport {setTimeout} from 'node:timers/promises';\nimport pTimeout from 'p-timeout';\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';\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';\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';\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';\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\n## AbortSignal\n\n> Modern alternative to `p-timeout`\n\nAsynchronous functions like `fetch` can accept an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal), which can be conveniently created with [`AbortSignal.timeout()`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static).\n\nThe advantage over `p-timeout` is that the promise-generating function (like `fetch`) is actually notified that the user is no longer expecting an answer, so it can interrupt its work and free resources.\n\n```js\n// Call API, timeout after 5 seconds\nconst response = await fetch('./my-api', {signal: AbortSignal.timeout(5000)});\n```\n\n```js\nasync function buildWall(signal) {\n\tfor (const brick of bricks) {\n\t\tsignal.throwIfAborted();\n\t\t// Or: if (signal.aborted) { return; }\n\n\t\tawait layBrick();\n\t}\n}\n\n// Stop long work after 60 seconds\nawait buildWall(AbortSignal.timeout(60_000))\n```\n\nYou can also combine multiple signals, like when you have a timeout *and* an `AbortController` triggered with a “Cancel” button click. You can use the upcoming [`AbortSignal.any()`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static) helper or [`abort-utils`](https://github.com/fregante/abort-utils/blob/main/source/merge-signals.md).\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/p-timeout\n","readmeFilename":"readme.md","_rev":"1-08be9987024c712b3b78b7957303474f"}