{"id":24290521,"url":"https://github.com/dutu/throttled-queue","last_synced_at":"2025-09-25T13:31:18.909Z","repository":{"id":42617690,"uuid":"259427595","full_name":"dutu/throttled-queue","owner":"dutu","description":"promise Task Scheduler and Rate Limiter for Node.js","archived":false,"fork":false,"pushed_at":"2023-03-06T12:26:25.000Z","size":4958,"stargazers_count":3,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-15T00:42:34.186Z","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/dutu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-27T19:11:06.000Z","updated_at":"2021-09-30T21:35:47.000Z","dependencies_parsed_at":"2023-02-07T01:49:25.776Z","dependency_job_id":null,"html_url":"https://github.com/dutu/throttled-queue","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dutu%2Fthrottled-queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dutu%2Fthrottled-queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dutu%2Fthrottled-queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dutu%2Fthrottled-queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dutu","download_url":"https://codeload.github.com/dutu/throttled-queue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234195791,"owners_count":18794357,"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":"2025-01-16T11:53:04.537Z","updated_at":"2025-09-25T13:31:18.538Z","avatar_url":"https://github.com/dutu.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"@dutu/throttled-queue\n====\n\n**throttled-queue** is a promise Task Scheduler and Rate Limiter for Node.js\n\n\n### Contents\n* [Changelog](#changelog)\n* [Installation](#installation)\n\n\n# Changelog\n\n#### 1.2.0\n* added methods `pause` and `start`\n\n#### 1.3.1\n* added support to `require` the module as CommonJS module. See note below for required dependencies to be installed as well  \n\n# Installation\n\n```\nnpm install --save \"git+https://github.com/dutu/throttled-queue.git\"\n```\n\u003e Note: when not using ES6 you should install the two packages below (which will emulate ES environment)\n\u003e```\n\u003enpm install --save core-js\n\u003enpm install --save regenerator-runtime \n\u003e```\n\u003eand use the following at the top of your main js file:\n\u003e```js\n\u003erequire(\"core-js/stable\")\n\u003erequire(\"regenerator-runtime/runtime\")\n\u003e```\n\n# Usage\n\nthrottled-queue is using [@dutu/rate-limiter](https://github.com/dutu/rate-limiter)\n\n## Constructor\n\n```js\nimport { TokenBucketLimiter, RollingWindowLimiter } from '@dutu/rate-limiter'\nconst rateLimiter = new TokenBucketLimiter({ bucketSize: 10, tokensPerInterval: 1, interval: 'sec'})\nconst throttledQueue = new ThrottledQueue({ rateLimiter, maxConcurrent: 1, minDelay: 0, timeout: 0 })\n\n```\n\n| Option         | Default | Description |\n|----------------|---------|-------------|\n| `rateLimiter`  |         | rate limiter for throttling the jobs |\n| `maxConcurrent`| `1`     | How many jobs can be executing at the same time. `0` is unlimited  |\n| `minDelay`     | `0`     | How long (ms) to wait after launching a job before launching another one |\n| `timeout`      | `0`     | The number of milliseconds a job is given to complete. Jobs that execute for longer than `timeout` ms will be failed with an error |\n\n\n### Methods\n\n### `add()`\n\nAdds a job to the queue\n\n```js\nthrottledQueue.add({ id : 'someId', priority: 5, timeout: 0 }, async () =\u003e {\n  // async function/promise\n  await delay(5000)\n})\n```\n\n| Option     | Default | Description |\n|------------|---------|-------------|\n| `id`       |         | Job Id |\n| `priority` | `5`     | Number from 0 to 9. Jobs with lower priority will always be executed first |\n| `timeout`  | `0`     | The number of milliseconds a job is given to complete. Jobs that execute for longer than `timeout` ms will be failed with an error. `0` means no timeout. |\n\n\n### `pause(durationMs)`\nPauses job execution for specified number of milliseconds.\nIf `null` is passed, job execution is paused indefinitely.\n\n```js\nthrottledQueue.pause(500)\nthrottledQueue.pause(null)\n```\n\n### `start()`\nStarts job execution (if it was paused with `pause()`)\n\n\n```js\nthrottledQueue.start()\n```\n\n### `clear()`\nClears the queue (deletes all queued jobs)\n\n```js\nthrottledQueue.clear()\n```\n\n### `getSize()`\nReturns queue size (for specified priority)\n\n```js\nthrottledQueue.getSize()\nthrottledQueue.getSize({ priority: 5 })\n```\n\n## Events\n\n### `enqueue`\n```js\nthrottledQueue.on(\"enqueue\", function (info) {\n  // This event is triggered when a job is added to the queue\n});\n```\n\n### `dequeue`\n```js\nthrottledQueue.on(\"dequeue\", function (info) {\n  // This event is triggered when a job is removed from the queue (for execution)\n});\n```\n\n### `execute`\n```js\nthrottledQueue.on(\"execute\", function (error, jobId) {\n  // This will be called when a job starts executing\n});\n```\n\n### `done`\n```js\nthrottledQueue.on(\"done\", function (error, jobId) {\n  // This will be called when a job execution completes successfully\n});\n```\n\n### `failed`\n```js\nthrottledQueue.on(\"failed\", function (error, jobId) {\n  // This will be called when a job fails\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdutu%2Fthrottled-queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdutu%2Fthrottled-queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdutu%2Fthrottled-queue/lists"}