{"_id":"set-delayed-interval","_rev":"4647306","name":"set-delayed-interval","description":"An asynchronous setInterval that is properly delayed using promises and can be delayed on boot","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"vascosantos","email":"santos.vasco10@gmail.com"}],"time":{"modified":"2026-04-10T20:21:58.000Z","created":"2020-11-24T15:28:52.547Z","1.0.0":"2020-11-24T15:28:52.547Z"},"users":{},"author":{"name":"Vasco Santos"},"repository":{"type":"git","url":"git+https://github.com/vasco-santos/set-delayed-interval.git"},"versions":{"1.0.0":{"name":"set-delayed-interval","version":"1.0.0","description":"An asynchronous setInterval that is properly delayed using promises and can be delayed on boot","main":"src/index.js","author":{"name":"Vasco Santos"},"scripts":{"test":"aegir test -t node -t browser","test:browser":"aegir test -t browser","test:node":"aegir test -t node","lint":"aegir lint","release":"aegir release --docs","release-minor":"aegir release --type minor --docs","release-major":"aegir release -t node -t browser --type major --docs","build":"aegir build"},"devDependencies":{"aegir":"^28.1.0","delay":"^4.4.0","p-wait-for":"^3.1.0","sinon":"^9.2.1"},"repository":{"type":"git","url":"git+https://github.com/vasco-santos/set-delayed-interval.git"},"keywords":["doh","dns","http"],"license":"MIT","bugs":{"url":"https://github.com/vasco-santos/set-delayed-interval/issues"},"homepage":"https://github.com/vasco-santos/set-delayed-interval#readme","contributors":[{"name":"Vasco Santos","email":"vasco.santos@ua.pt"}],"gitHead":"38bc00f8a5a45d22233e2d46ae31a4701509654f","_id":"set-delayed-interval@1.0.0","_nodeVersion":"12.19.0","_npmVersion":"6.14.8","dist":{"shasum":"1f7c065780a365f10250f8a80e2be10175ea0388","size":3618,"noattachment":false,"key":"/set-delayed-interval/-/set-delayed-interval-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/set-delayed-interval/download/set-delayed-interval-1.0.0.tgz"},"_npmUser":{"name":"vascosantos","email":"vasco.santos@moxy.studio"},"directories":{},"maintainers":[{"name":"vascosantos","email":"santos.vasco10@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/set-delayed-interval_1.0.0_1606231732429_0.4759233915617085"},"_hasShrinkwrap":false,"publish_time":1606231732547,"_cnpm_publish_time":1606231732547,"_cnpmcore_publish_time":"2021-12-18T06:56:49.315Z"}},"readme":"# set-delayed-interval\n\n[![Build Status](https://travis-ci.org/vasco-santos/set-delayed-interval.svg?branch=main)](https://travis-ci.org/vasco-santos/set-delayed-interval)\n[![dependencies Status](https://david-dm.org/vasco-santos/set-delayed-interval/status.svg)](https://david-dm.org/vasco-santos/set-delayed-interval)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\n> An asynchronous setInterval that is properly delayed using promises and can be delayed on boot\n\n## Motivation\n\nThe native implementation of `setInterval` expects synchronous functions to be executed. When asynchronous functions are provided, some unexpected behaviors might appear. This module mimics the `setInterval` native functionality with support for promises in a way that the interval timer is delayed by the execution of that promise. This results in equal stop times for each run, as soon as the promise is resolved.\n\nFor some scenarios, it is useful to add a start delay before running a recurrent task. This module also supports a custom delay before the interval starts. The `clearDelayedInterval` can stop both the initial delay and the interval.\n\n## Install\n\n```sh\nnpm i set-delayed-interval\n```\n\n## Usage\n\n```js\nconst { setDelayedInterval, clearDelayedInterval } = require('set-delayed-interval')\n\nconst task = async () => {\n  /// ....\n}\n\n// After 100ms, run the task recurrently with 50ms intervals\nconst id = setDelayedInterval(task, 50, 100)\n\n// ...\nclearDelayedInterval(id)\n```\n\n\n## API\n\n### `setDelayedInterval`\n\n#### Parameters\n\n|  Name  | Type | Description |\n|--------|------|-------------|\n|  task  | `() => Promise` | recurrent task to run |\n| interval | `number` | interval between each task (in ms) |\n| [delay] | `number` | delay before first run (in ms). Defaults to `interval`. |\n\n#### Returns\n\n| Type | Description |\n|------|-------------|\n| `string` | interval id |\n\n### `clearDelayedInterval`\n\n#### Parameters\n\n|  Name  | Type | Description |\n|--------|------|-------------|\n|  id  | `string` | interval id to clear |\n\n## Error Handling\n\nThis module throws task errors on the global context. For handling your tasks errors, it is recommended to wrap the task async code with a `try catch` block, or your can catch the global errors with `process.once('uncaughtException', (err) => {})` in Node.js or `window.onerror = (err) => {}` in the browser.\n\n## Contribute\n\nFeel free to dive in! [Open an issue](https://github.com/vasco-santos/set-delayed-interval/issues/new) or submit PRs.\n\n## License\n\n[MIT](LICENSE) © Vasco Santos\n","_attachments":{},"homepage":"https://github.com/vasco-santos/set-delayed-interval#readme","bugs":{"url":"https://github.com/vasco-santos/set-delayed-interval/issues"},"license":"MIT"}