{"_id":"unlimited-timeout","_rev":"4106774","name":"unlimited-timeout","description":"setTimeout and setInterval that work with delays longer than 24.8 days","dist-tags":{"latest":"0.1.0"},"maintainers":[{"name":"sindresorhus","email":""}],"time":{"modified":"2026-01-11T18:56:31.000Z","created":"2025-10-31T15:57:08.761Z","0.1.0":"2025-10-31T15:57:08.761Z"},"users":{},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"repository":{"type":"git","url":"git+https://github.com/sindresorhus/unlimited-timeout.git"},"versions":{"0.1.0":{"name":"unlimited-timeout","version":"0.1.0","description":"setTimeout and setInterval that work with delays longer than 24.8 days","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/unlimited-timeout.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","default":"./index.js"},"sideEffects":false,"engines":{"node":">=20"},"scripts":{"test":"xo && node --test && tsd"},"keywords":["timeout","settimeout","setinterval","unlimited","long","extended","delay","timer","overflow","max","maximum","large","big","infinite","schedule","safe"],"devDependencies":{"@types/node":"^24.8.1","tsd":"^0.33.0","xo":"^1.2.2"},"gitHead":"8666d2e302edabf63b9e0f6716a6528c000737a5","types":"./index.d.ts","_id":"unlimited-timeout@0.1.0","bugs":{"url":"https://github.com/sindresorhus/unlimited-timeout/issues"},"homepage":"https://github.com/sindresorhus/unlimited-timeout#readme","_nodeVersion":"20.19.5","_npmVersion":"11.6.1","dist":{"shasum":"a530bc85aac4502abb8342dd6ec66bb56d6fa22d","size":4383,"noattachment":false,"key":"/unlimited-timeout/-/unlimited-timeout-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/unlimited-timeout/download/unlimited-timeout-0.1.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/unlimited-timeout_0.1.0_1761926228541_0.8583880384340719"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-10-31T15:57:08.761Z","publish_time":1761926228761,"_source_registry_name":"default","_cnpm_publish_time":1761926228761}},"readme":"# unlimited-timeout\n\n> `setTimeout` and `setInterval` that work with delays longer than 24.8 days\n\nJavaScript's built-in `setTimeout` and `setInterval` have a maximum delay of 2^31-1 milliseconds (approximately 24.8 days). Attempting to use a longer delay causes the timer fires immediately with a 1ms delay instead of waiting for the intended duration.\n\nThis package provides drop-in replacements that handle arbitrarily long delays by automatically breaking them into smaller chunks.\n\n## Install\n\n```sh\nnpm install unlimited-timeout\n```\n\n## Usage\n\n```js\nimport {setTimeout, clearTimeout} from 'unlimited-timeout';\n\n// Schedule a callback for 30 days in the future\n// With native setTimeout, this would fire immediately and show a warning in Node.js\nconst timeout = setTimeout(() => {\n\tconsole.log('30 days have passed!');\n}, 30 * 24 * 60 * 60 * 1000);\n\n// Cancel it if needed\nclearTimeout(timeout);\n```\n\n```js\nimport {setInterval, clearInterval} from 'unlimited-timeout';\n\n// Call a function every 30 days\nconst interval = setInterval(() => {\n\tconsole.log('Another 30 days have passed!');\n\t// Do monthly cleanup, send reports, etc.\n}, 30 * 24 * 60 * 60 * 1000);\n\n// Stop it later\nclearInterval(interval);\n```\n\n## Notes\n\n- The timeout/interval objects returned by this package are not interchangeable with native timeout IDs.\n- You must use the `clearTimeout`/`clearInterval` functions from this package, not the native ones.\n- For delays under ~24.8 days, this package adds minimal overhead as it doesn't need to chunk.\n- This package works in both Node.js and browsers.\n\n## API\n\n### setTimeout(callback, delay, ...arguments)\n\nSchedule a function to be called after a delay, even if the delay exceeds JavaScript's built-in `setTimeout` maximum of ~24.8 days.\n\nUnlike the native `setTimeout`, this function handles arbitrarily long delays by breaking them into smaller chunks internally.\n\nReturns a `Timeout` object that can be passed to `clearTimeout()`.\n\n#### callback\n\nType: `Function`\n\nThe function to call after the delay.\n\n#### delay\n\nType: `number` (any value will be coerced to number)\\\nDefault: `0`\n\nThe delay in milliseconds. Like native `setTimeout`, the value is coerced to a number. Invalid values (NaN, negative numbers) are clamped to `0` (immediate firing). `Infinity` means wait forever (never fire).\n\n#### arguments\n\nType: `any[]`\n\nOptional arguments to pass to the callback.\n\n```js\nimport {setTimeout} from 'unlimited-timeout';\n\n// Pass arguments to the callback\nsetTimeout((name, count) => {\n\tconsole.log(`Hello ${name}, called ${count} times`);\n}, 1000, 'Alice', 42);\n```\n\n### clearTimeout(timeout)\n\nCancel a timeout created with `setTimeout()`.\n\nThis function is safe to call multiple times with the same timeout object, and it's safe to call with `undefined` or `null`.\n\n#### timeout\n\nType: `Timeout | undefined | null`\n\nThe timeout object to cancel.\n\n### setInterval(callback, delay, ...arguments)\n\nSchedule a function to be called repeatedly with a delay between each call, even if the delay exceeds JavaScript's built-in `setInterval` maximum of ~24.8 days.\n\nUnlike the native `setInterval`, this function handles arbitrarily long delays by breaking them into smaller chunks internally.\n\nReturns a `Timeout` object that can be passed to `clearInterval()`.\n\n#### callback\n\nType: `Function`\n\nThe function to call after each delay.\n\n#### delay\n\nType: `number` (any value will be coerced to number)\\\nDefault: `0`\n\nThe delay in milliseconds between each call. Like native `setInterval`, the value is coerced to a number. Invalid values (NaN, negative numbers) are clamped to `0` (immediate firing). `Infinity` means wait forever (never fire).\n\n#### arguments\n\nType: `any[]`\n\nOptional arguments to pass to the callback.\n\n### clearInterval(interval)\n\nCancel an interval created with `setInterval()`.\n\nThis function is safe to call multiple times with the same interval object, and it's safe to call with `undefined` or `null`.\n\n#### interval\n\nType: `Timeout | undefined | null`\n\nThe interval object to cancel.\n\n### MAX_TIMEOUT\n\nType: `number`\\\nValue: `2_147_483_647`\n\nMaximum safe timeout value for `setTimeout` in JavaScript (2^31-1 milliseconds). This is approximately 24.8 days.\n\n## Related\n\n- [delay](https://github.com/sindresorhus/delay) - Delay a promise a specified amount of time\n","_attachments":{},"homepage":"https://github.com/sindresorhus/unlimited-timeout#readme","bugs":{"url":"https://github.com/sindresorhus/unlimited-timeout/issues"},"license":"MIT"}