{"id":22092240,"url":"https://github.com/pirxpilot/limiter","last_synced_at":"2025-03-23T23:45:35.845Z","repository":{"id":7521586,"uuid":"8872525","full_name":"pirxpilot/limiter","owner":"pirxpilot","description":"Limits the rate of function calls to one per period.","archived":false,"fork":false,"pushed_at":"2022-09-07T07:34:47.000Z","size":23,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-04-29T19:22:03.661Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pirxpilot.png","metadata":{"files":{"readme":"Readme.md","changelog":"History.md","contributing":null,"funding":null,"license":"License.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-03-19T06:45:09.000Z","updated_at":"2022-08-31T11:24:34.000Z","dependencies_parsed_at":"2023-01-11T17:11:50.379Z","dependency_job_id":null,"html_url":"https://github.com/pirxpilot/limiter","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirxpilot%2Flimiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirxpilot%2Flimiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirxpilot%2Flimiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirxpilot%2Flimiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pirxpilot","download_url":"https://codeload.github.com/pirxpilot/limiter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245186927,"owners_count":20574554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-01T03:08:51.385Z","updated_at":"2025-03-23T23:45:35.821Z","avatar_url":"https://github.com/pirxpilot.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM version][npm-image]][npm-url]\n[![Build Status][build-image]][build-url]\n[![Dependency Status][deps-image]][deps-url]\n\n# limiter\n\n  Limits the rate of function calls to one per period. It delays but does not throttle the calls.\n  Useful when your codes needs to behave well when calling rate limited API.\n\n  If you need something more flexible use [rate limiter](https://npmjs.org/package/limiter)\n\n## Installation\n\n    $ npm install --save limiter-component\n\n## Usage\n\nCreate `limiter` with desired `interval` setting. Call `trigger` passing a function that you want to\nlimit.\n\n```javascript\nvar limiter = require('limiter'),\n\tl = limiter(500); // interval in millis\n\nfunction doThis() {\n  // this is called at most twice per second\n}\n\nfunction doThat() {\n  // you can rate limit different functions\n}\n\n\nl.trigger(doThis);\nl.trigger(doThat);\nl.trigger(doThis);\nl.trigger(function() {\n\tl.penalty(); // wait a bit longer the next time\n});\nl.trigger(doThat);\nl.trigger(function() {\n\tl.skip(); // don't wait at all the next time\n});\nl.trigger(doThis);\n\n// you can also wait for the trigger using Promises\n\nawait l.trigger(); // note that `fn` is optional\n// trigger has been resolved\n```\n\n## API\n\n### limiter(interval, [penaltyInterval])\n\nCreate `limiter` with desired `interval` (in millis). Optional `penaltyInterval` is used instead of\n`interval` if `limiter.penalty()` has been called at least once since last limited function has been\ntriggered.\n\n### trigger(fn)\n\nAdd `fn` to `limiter` queue. It will be called when `interval` elapsed since another function from\nthe queue was called. Returns a promise, which is resolved when `fn` is called.\n\n### penalty()\n\nMake limiter use `penaltyInterval` before triggering next function.\n\n### skip()\n\nMake limiter trigger next function immediately.\n\n### cancel()\n\nEmpty `limiter` queue. Remove all pending trigger request. No methods from the queue is called after\n`cancel`.\n\n## License\n\n  MIT\n\n[npm-image]: https://img.shields.io/npm/v/limiter-component\n[npm-url]: https://npmjs.org/package/limiter-component\n\n[build-url]: https://github.com/pirxpilot/limiter/actions/workflows/check.yaml\n[build-image]: https://img.shields.io/github/workflow/status/pirxpilot/limiter/check\n\n[deps-image]: https://img.shields.io/librariesio/release/npm/limiter-component\n[deps-url]: https://libraries.io/npm/limiter-component\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpirxpilot%2Flimiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpirxpilot%2Flimiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpirxpilot%2Flimiter/lists"}