{"id":15984230,"url":"https://github.com/metcoder95/tiny-pool","last_synced_at":"2026-03-02T22:02:03.724Z","repository":{"id":58475096,"uuid":"531973443","full_name":"metcoder95/tiny-pool","owner":"metcoder95","description":"Extremely simplistic and tiny AsyncPool for limiting concurrency of async operations ","archived":false,"fork":false,"pushed_at":"2024-08-19T06:37:12.000Z","size":56,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-28T06:03:49.705Z","etag":null,"topics":["await","concurrency","nodejs","promise","task"],"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/metcoder95.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-02T15:07:53.000Z","updated_at":"2024-07-31T10:18:10.000Z","dependencies_parsed_at":"2023-11-06T09:46:50.947Z","dependency_job_id":"a331493f-f315-4cf5-950a-36a0019c8b0c","html_url":"https://github.com/metcoder95/tiny-pool","commit_stats":{"total_commits":38,"total_committers":2,"mean_commits":19.0,"dds":"0.39473684210526316","last_synced_commit":"9686520614177aad3c785511e063ade8d1b34f11"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":"metcoder95/lib_template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metcoder95%2Ftiny-pool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metcoder95%2Ftiny-pool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metcoder95%2Ftiny-pool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metcoder95%2Ftiny-pool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/metcoder95","download_url":"https://codeload.github.com/metcoder95/tiny-pool/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244133890,"owners_count":20403508,"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":["await","concurrency","nodejs","promise","task"],"created_at":"2024-10-08T02:05:13.171Z","updated_at":"2026-03-02T22:02:03.650Z","avatar_url":"https://github.com/metcoder95.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @metcoder95/tiny-pool\n\nExtremely simplistic and tiny AsyncPool for limiting concurrency of async operations.\nContains zero dependencies beside Node.js native ones.\n\n## Examples\n\n### JavaScript\n\n```js\nconst { AsyncPool } = require('@metcoder95/tiny-pool');\nasync () =\u003e {\n  const asyncPool = new AsyncPool({ maxConcurrent: 5, maxEnqueued: 100 });\n\n  asyncPool.on('flushed', () =\u003e console.log('queue is flushed'));\n  asyncPool.on('drained', () =\u003e console.log('pool is drained'));\n\n  for (let i = 0; i \u003c 20; i++) {\n    asyncPool.run(() =\u003e {\n      return new Promise((resolve) =\u003e {\n        setTimeout(() =\u003e {\n          resolve(i);\n        }, 1000);\n      });\n    });\n\n    if (i === 10) {\n      const result = await asyncPool.drain();\n      console.log('Queue drained:', result);\n    } else if (i === 15) {\n      const result = await asyncPool.flush();\n      console.log('Pool flushed:', result);\n    }\n  }\n\n  await once(asyncPool, 'idle').then(console.log('done'));\n};\n```\n\n### TypeScript\n\n```ts\nimport { AsyncPool, AsyncPoolOptions } from '@metcoder95/tiny-pool';\nasync () =\u003e {\n  const options: AsyncPoolOptions = {\n    maxEnqueued: 100,\n  };\n  const asyncPool = new AsyncPool({ maxConcurrent: 5, maxEnqueued: 100 });\n\n  asyncPool.on('flushed', () =\u003e console.log('queue is flushed'));\n  asyncPool.on('drained', () =\u003e console.log('pool is drained'));\n\n  for (let i = 0; i \u003c 20; i++) {\n    asyncPool.run(() =\u003e {\n      return new Promise((resolve) =\u003e {\n        setTimeout(() =\u003e {\n          resolve(i);\n        }, 1000);\n      });\n    });\n\n    if (i === 10) {\n      const result = await asyncPool.drain();\n      console.log('Queue drained:', result);\n    } else if (i === 15) {\n      const result = await asyncPool.flush();\n      console.log('Pool flushed:', result);\n    }\n  }\n\n  await once(asyncPool, 'idle').then(console.log('done'));\n};\n```\n\n## Usage\n\n### Options\n```ts\ntype AsyncPoolOptions = {\n  /**\n   * Indicates the maximum number of concurrent tasks being executed\n   *\n   * @default 5\n   * @type {number}\n   */\n  maxConcurrent?: number;\n  /**\n   * Specifies the maximum number of tasks being enqueued for posterior execution\n   * @default 10\n   * @type {number}\n   */\n  maxEnqueued?: number;\n};\n```\n\n### APIs\n\n#### `run`\n\n**Signature**\n`run\u003cResult = unknown\u003e(task: Promise\u003cResult\u003e): AsyncPoolTask\u003cResult\u003e`\n\nExecutes the given async task. The task should return a Promise.\nThe function returns a Promise that will either resolve with the\nvalue returned by the Promise or reject in case of a failure\n\n#### `clear`\n\n**Signature**\n`clear(): void`\n\nThe function will clear the queue, avoiding the execution of\nthe tasks within.\n\n#### `flush`\n\u003ca id=\"flush\"\u003e\u003c/a\u003e\n\n**Signature**\n`flush(): Promise\u003cAsyncPoolTask[]\u003e`\n\nWill flush all the enqueued and current running tasks\nblocking for any new incoming one of being enqueued.\nWill emit the event `flushed` once the queue is empty.\n\n#### `drain`\n\u003ca id=\"drain\"\u003e\u003c/a\u003e\n\n**Signature**\n`drain(): Promise\u003cAsyncPoolTask[]\u003e`\n\nIt will until all the tasks that are currently running are\ndone being executed. Enqueueing is still possible but it will\nnot execute any enqueued tasks until the draining is done.\nIt will emit the event `drained` once done.\n\n### Events\n\nThe `AsyncPool` class extends from the [`EventEmitter`](https://nodejs.org/api/events.html#class-eventemitter) from Node.js.\nFor instance is possible to listen for a couple of events that might be helpful when using the pool.\n\n#### `flushed`\n\nIt indicates the full pool has been flushed. Is emitted after the execution of the [`flush`](#flush) function.\n\n#### `drained`\n\nWill be emitted onceall the running tasks are being executed. It's only emitted after the execution of [`drain`](#drain) function.\n\n#### `idle`\n\nOnly emitted when the queue is empty and the current tasks finished its execution. This can be a good moment to continue appending more tasks to the pool.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetcoder95%2Ftiny-pool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmetcoder95%2Ftiny-pool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetcoder95%2Ftiny-pool/lists"}