{"_id":"@aherve/async-pool","_rev":"5-b95dec371bf1c87be854fa71fa6c09d0","name":"@aherve/async-pool","dist-tags":{"latest":"1.1.0"},"versions":{"0.0.1":{"name":"@aherve/async-pool","version":"0.0.1","keywords":["concurrent","queue","pool","async","promise","generator"],"author":{"name":"Aurélien Hervé","email":"mail@aurelien-herve.com"},"license":"GPL-3.0-or-later","_id":"@aherve/async-pool@0.0.1","maintainers":[{"name":"aherve","email":"mail@aurelien-herve.com"}],"homepage":"https://github.com/aherve/async-pool","bugs":{"url":"https://github.com/aherve/async-pool/issues"},"dist":{"shasum":"62eb933a3d50331421026ec28488448cdc34264d","tarball":"https://registry.npmjs.org/@aherve/async-pool/-/async-pool-0.0.1.tgz","fileCount":7,"integrity":"sha512-Az5wbBV3EhRexRuik8BRUwb/rh10MNp+PuDDRrudCM/HIwUy/qZU0mEtmOdIyLYn+iV3kulylpQUqLC6PFPLpg==","signatures":[{"sig":"MEYCIQDVS3D3KzbvOs0lRJpcGWS3LZTPwV15h+JsOLGMxqUHpgIhAJDd0BzpNaMXy3vRtYWueY2sxy/LlaZ6YpzZmCc/2mgc","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":21503},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","exports":{".":{"import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"68f48d00d51f693dee5ffd1230b883af572ab677","scripts":{"doc":"typedoc","lint":"eslint ./src ./tests","test":"node --experimental-strip-types ./tests/**","build":"rm -rf dist/* && tsc && rollup dist/index.js --file dist/index.cjs --format cjs","compile":"tsc --noEmit","test:watch":"node --experimental-strip-types --watch ./tests/**"},"_npmUser":{"name":"aherve","email":"mail@aurelien-herve.com"},"repository":{"url":"git+https://github.com/aherve/async-pool.git","type":"git"},"_npmVersion":"11.4.2","description":"A concurrent pool for Node.js and browsers, supporting async functions, promises, and generators.","directories":{},"_nodeVersion":"24.4.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"pnpm@10.5.2","devDependencies":{"jiti":"^2.5.1","eslint":"^9.32.0","rollup":"^4.46.1","globals":"^16.3.0","typedoc":"^0.28.7","typescript":"^5.8.3","@types/node":"^24.1.0","typescript-eslint":"^8.38.0","typedoc-plugin-markdown":"^4.7.1"},"_npmOperationalInternal":{"tmp":"tmp/async-pool_0.0.1_1753808372914_0.8671898220727596","host":"s3://npm-registry-packages-npm-production"}},"0.0.2":{"name":"@aherve/async-pool","version":"0.0.2","keywords":["concurrent","queue","pool","async","promise","generator"],"author":{"name":"Aurélien Hervé","email":"mail@aurelien-herve.com"},"license":"GPL-3.0-or-later","_id":"@aherve/async-pool@0.0.2","maintainers":[{"name":"aherve","email":"mail@aurelien-herve.com"}],"homepage":"https://github.com/aherve/async-pool","bugs":{"url":"https://github.com/aherve/async-pool/issues"},"dist":{"shasum":"22f776b9918244195c3daca320fce78bfc0b1b22","tarball":"https://registry.npmjs.org/@aherve/async-pool/-/async-pool-0.0.2.tgz","fileCount":7,"integrity":"sha512-+gzEIkfX+GJEhYDFbs9PQwMVSMGWvsgtVKrcDwK82jvDBDw4hUvNItBLXAOXQVc6UlVLlr8YXt/XhAHZVouabQ==","signatures":[{"sig":"MEYCIQCU9fcJtZJNSe4YR86s94ko1wwolpGhxok8IcljLXVdbgIhAJToKmPM0NdG+qFiSmuf9TczWwpRvIjPmByWOtc5ndU2","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":21503},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","exports":{".":{"import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"3c872e1e61e7932eda7e4946a4250d52e2732df1","scripts":{"doc":"typedoc","lint":"eslint ./src ./tests","test":"node --experimental-strip-types ./tests/**","build":"rm -rf dist/* && tsc && rollup dist/index.js --file dist/index.cjs --format cjs","compile":"tsc --noEmit","test:watch":"node --experimental-strip-types --watch ./tests/**"},"_npmUser":{"name":"aherve","email":"mail@aurelien-herve.com"},"repository":{"url":"git+https://github.com/aherve/async-pool.git","type":"git"},"_npmVersion":"10.9.2","description":"A concurrent pool for Node.js and browsers, supporting async functions, promises, and generators.","directories":{},"_nodeVersion":"23.11.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"pnpm@10.5.2","devDependencies":{"jiti":"^2.5.1","eslint":"^9.32.0","rollup":"^4.46.1","globals":"^16.3.0","typedoc":"^0.28.7","typescript":"^5.8.3","@types/node":"^24.1.0","typescript-eslint":"^8.38.0","typedoc-plugin-markdown":"^4.7.1"},"_npmOperationalInternal":{"tmp":"tmp/async-pool_0.0.2_1753808697806_0.25606679229572227","host":"s3://npm-registry-packages-npm-production"}},"1.0.0":{"name":"@aherve/async-pool","version":"1.0.0","keywords":["concurrent","queue","pool","async","promise","generator"],"author":{"name":"Aurélien Hervé","email":"mail@aurelien-herve.com"},"license":"GPL-3.0-or-later","_id":"@aherve/async-pool@1.0.0","maintainers":[{"name":"aherve","email":"mail@aurelien-herve.com"}],"homepage":"https://github.com/aherve/async-pool","bugs":{"url":"https://github.com/aherve/async-pool/issues"},"dist":{"shasum":"ebd2c93f9ab940c5ac8e21b12531a82aa0f6681e","tarball":"https://registry.npmjs.org/@aherve/async-pool/-/async-pool-1.0.0.tgz","fileCount":7,"integrity":"sha512-X+oyTtOxuxzySueWT3XX3Boq3BNUwu8CYWTTcBNgkFgL2WQQu6eEbDdbu854aMBRFoZiKo7GDhLvXMXJaykIRA==","signatures":[{"sig":"MEUCIDrGWQI2YsWc/XmPY+ffkyV2MWFLCIxJL30M4XrA3tvJAiEA5Zn3CjFTtFyHmpEAm+cnWPuIzLSg73reWZMFTR+PD7w=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":21527},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","exports":{".":{"import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"2797985df79017d0012d77492b18ba2761d8f58a","scripts":{"doc":"typedoc","lint":"eslint ./src ./tests","test":"node --experimental-strip-types ./tests/**","build":"rm -rf dist/* && tsc && rollup dist/index.js --file dist/index.cjs --format cjs","compile":"tsc --noEmit","test:watch":"node --experimental-strip-types --watch ./tests/**"},"_npmUser":{"name":"aherve","email":"mail@aurelien-herve.com"},"repository":{"url":"git+https://github.com/aherve/async-pool.git","type":"git"},"_npmVersion":"10.9.2","description":"A concurrent pool for Node.js and browsers, supporting consuming result via promises, and generators.","directories":{},"_nodeVersion":"23.11.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"pnpm@10.5.2","devDependencies":{"jiti":"^2.5.1","eslint":"^9.32.0","rollup":"^4.46.1","globals":"^16.3.0","typedoc":"^0.28.7","typescript":"^5.8.3","@types/node":"^24.1.0","typescript-eslint":"^8.38.0","typedoc-plugin-markdown":"^4.7.1"},"_npmOperationalInternal":{"tmp":"tmp/async-pool_1.0.0_1753809199557_0.7252842413713023","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@aherve/async-pool","version":"1.0.1","keywords":["concurrent","queue","pool","async","promise","generator"],"author":{"name":"Aurélien Hervé","email":"mail@aurelien-herve.com"},"license":"GPL-3.0-or-later","_id":"@aherve/async-pool@1.0.1","maintainers":[{"name":"aherve","email":"mail@aurelien-herve.com"}],"homepage":"https://github.com/aherve/async-pool","bugs":{"url":"https://github.com/aherve/async-pool/issues"},"dist":{"shasum":"2d4350b208c57233ec4820794669101e733f8dc3","tarball":"https://registry.npmjs.org/@aherve/async-pool/-/async-pool-1.0.1.tgz","fileCount":8,"integrity":"sha512-kzwjniIOTFnNnZZVsz2qMuQbL79C024PEPPKZSmHsFfr4HDGyaPwPFkK5+v2+OmVkMOiuxe/MBUsSYO3HZqRPQ==","signatures":[{"sig":"MEYCIQDMYajY88r5W92wu1XbfdiMTrETlSivEnfjoU/R06aGiAIhAM7oO3i9ABM7uqU8TDcOl8/sk8bFwC3yCepdXNlSRGl8","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":56819},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","exports":{".":{"import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"aef3448197196fe4d71c4d1c2021b342f7c2e5ab","scripts":{"doc":"typedoc","lint":"eslint ./src ./tests","test":"node --experimental-strip-types ./tests/**","build":"rm -rf dist/* && tsc && rollup dist/index.js --file dist/index.cjs --format cjs","compile":"tsc --noEmit","test:watch":"node --experimental-strip-types --watch ./tests/**"},"_npmUser":{"name":"aherve","email":"mail@aurelien-herve.com"},"repository":{"url":"git+https://github.com/aherve/async-pool.git","type":"git"},"_npmVersion":"10.9.2","description":"A concurrent pool for Node.js and browsers, supporting consuming result via promises, and generators.","directories":{},"_nodeVersion":"23.11.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"pnpm@10.5.2","devDependencies":{"jiti":"^2.5.1","eslint":"^9.32.0","rollup":"^4.46.1","globals":"^16.3.0","typedoc":"^0.28.7","typescript":"^5.8.3","@types/node":"^24.1.0","typescript-eslint":"^8.38.0","typedoc-plugin-markdown":"^4.7.1"},"_npmOperationalInternal":{"tmp":"tmp/async-pool_1.0.1_1753824724405_0.9268347700199682","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@aherve/async-pool","version":"1.1.0","repository":{"type":"git","url":"git+https://github.com/aherve/async-pool.git"},"homepage":"https://github.com/aherve/async-pool","publishConfig":{"access":"public"},"description":"A concurrent pool for Node.js and browsers, supporting consuming result via promises, and generators.","keywords":["concurrent","queue","pool","async","promise","generator"],"license":"GPL-3.0-or-later","type":"module","main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"import":"./dist/index.js","require":"./dist/index.cjs"}},"scripts":{"lint":"eslint ./src ./tests","test":"node --experimental-strip-types ./tests/**","test:watch":"node --experimental-strip-types --watch ./tests/**","compile":"tsc --noEmit","build":"rm -rf dist/* && tsc && rollup dist/index.js --file dist/index.cjs --format cjs","doc":"typedoc"},"author":{"name":"Aurélien Hervé","email":"mail@aurelien-herve.com"},"packageManager":"pnpm@10.5.2","devDependencies":{"@types/node":"^24.1.0","eslint":"^9.32.0","globals":"^16.3.0","jiti":"^2.5.1","rollup":"^4.46.1","typedoc":"^0.28.7","typedoc-plugin-markdown":"^4.7.1","typescript":"^5.8.3","typescript-eslint":"^8.38.0"},"_id":"@aherve/async-pool@1.1.0","gitHead":"c7278b8172752d980109f94b9353d50f96a7ff15","bugs":{"url":"https://github.com/aherve/async-pool/issues"},"_nodeVersion":"23.11.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-o96iayfKE+hSUq0AWs6yT0ZJfSBxryCj7i2oYcKxUlqqYTP10djUTuiV7LFeMaeBEpHdU0YMuNPoMrhyKnl0Xg==","shasum":"3e1361a642f0bd75a9b25c0aab471f2b8b2f5f00","tarball":"https://registry.npmjs.org/@aherve/async-pool/-/async-pool-1.1.0.tgz","fileCount":8,"unpackedSize":62014,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCnMdlXgKRVNf2p3VEufECR/jQDVIIpasxdQFq+kH9GzwIgcZnarAUJgN6yqR7ixop1ZoVjocgEewJeR/iGHxT7Mak="}]},"_npmUser":{"name":"aherve","email":"mail@aurelien-herve.com"},"directories":{},"maintainers":[{"name":"aherve","email":"mail@aurelien-herve.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/async-pool_1.1.0_1753951657629_0.6384587217197446"},"_hasShrinkwrap":false}},"time":{"created":"2025-07-29T16:59:32.802Z","modified":"2025-07-31T08:47:37.953Z","0.0.1":"2025-07-29T16:59:33.136Z","0.0.2":"2025-07-29T17:04:57.978Z","1.0.0":"2025-07-29T17:13:19.750Z","1.0.1":"2025-07-29T21:32:04.588Z","1.1.0":"2025-07-31T08:47:37.803Z"},"bugs":{"url":"https://github.com/aherve/async-pool/issues"},"author":{"name":"Aurélien Hervé","email":"mail@aurelien-herve.com"},"license":"GPL-3.0-or-later","homepage":"https://github.com/aherve/async-pool","keywords":["concurrent","queue","pool","async","promise","generator"],"repository":{"type":"git","url":"git+https://github.com/aherve/async-pool.git"},"description":"A concurrent pool for Node.js and browsers, supporting consuming result via promises, and generators.","maintainers":[{"name":"aherve","email":"mail@aurelien-herve.com"}],"readme":"# Async Pool\n\nA concurrent pool for Node.js and browsers, supporting consuming result via promises, and generators.\n\n![NPM Version](https://img.shields.io/npm/v/%40aherve%2Fasync-pool)\n![NPM Downloads](https://img.shields.io/npm/dm/%40aherve%2Fasync-pool)\n![NPM License](https://img.shields.io/npm/l/%40aherve%2Fasync-pool)\n![npm bundle size](https://img.shields.io/bundlephobia/min/%40aherve%2Fasync-pool)\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/aherve/async-pool/test.yml)\n\n\n## Features\n\n- **Concurrency Control:** Limit the number of promises running at the same time.\n- **Memory Efficiency:** Can process large numbers of tasks without having to build a large arrays of results.\n- **Flexible API:** Supports both async iteration and promise-based consumption.\n\n## Installation\n\n```bash\nnpm install @aherve/async-pool\n```\n\n```typescript\n// with TypeScript or ES Modules\nimport { AsyncPool } from \"@aherve/async-pool\";\n\n// or with CommonJS\nconst AsyncPool = require(\"@aherve/async-pool\").AsyncPool;\n```\n\n## Usage\n\n### Consume results as a stream\n\n```typescript\nconst pool = new AsyncPool<boolean>() // generic can optionally be used\n  .withConcurrency(10)\n  .withRetries(3); // default number of retries for each task unless specified at task level\n\n\n// Processing will start as soon as the first task is added\nfor await (const document of largeDBCollectionScanner) {\n  pool.add({\n    task: () => updateDBDoc(document), // assuming this returns a Promise<boolean>\n  })\n}\n\n// results can be consumed as a stream, without building a large array of results\nlet total = 0;\nfor await (const update of pool.results()) {\n  if update.changed { \n    total++\n  }\n}\n\nconsole.log(\"Successfully updated\", total, \"documents\");\n```\n\n#### Safe mode\n\nAlternatively, safe mode can be used to avoid throwing, and instead return errors in the results stream. When using this mode, the pool will process all taksks, even if some fail, and you can handle errors gracefully.\n\n```typescript\nfor await (const res of pool.safeResults()) {\n    if (res.success) {\n        console.log(\"Task succeeded:\", res.data);\n    } else {\n        console.error(\"Task failed:\", res.error);\n    }\n}\n```\n\n### Headless processsing\n\nFire and forget tasks, with controlled concurrency and retries\n\n```typescript\n\nconst pool = new AsyncPool()\n  .withConcurrency(10)\n  .withRetries(3)\n  .add({ task: () => doSomethingAsync() })\n  .add({ task: () => doSomethingElse() })\n\n// wait until all tasks are processed\nawait pool.waitForTermination();\n\n// At this point, all promises have been resolved successfully\n```\n\n### Promise-based consumption\n\nSimilar to `Promise.all`, but with controlled concurrency and builtin retries\n\n```typescript\nconst pool = new AsyncPool();\n\npool.add({ task: async () => 1 });\npool.add({ task: async () => true });\npool.add({ task: async () => \"hello\" });\n\nconst results = await pool.all();\nconsole.log(results); // [1, true, \"hello\"], order not guaranteed (especially if retries happened)\n```\n\n#### Safe mode\n\n`all` can also be used in safe mode:\n\n```typescript\nconst pool = new AsyncPool();\nconst error = new Error('nope');\n\npool.add({ task: async () => 1 });\npool.add({ task: async () => { throw error } });\npool.add({ task: async () => \"hello\" });\nconst results = await pool.safeAll();\n/**\n* [\n*   { success: true, data: 1 },\n*   { success: false, error },\n*   { success: true, data: \"hello\" }\n* ]\n*/\n```\n\n### Using generic typings\n\nYou can specify a generic type for the `AsyncPool` to enforce type safety on the results of the tasks. If you don't specify a type, it will default to `unknown`, allowing any type of result.\n\n```typescript\nconst typedPool = new AsyncPool<string>();\n\ntypedPool.add({ task: async () => \"hello\" }); // OK\ntypedPool.add({ task: async () => 1 }); // ❌ Error: Type 'Promise<number>' is not assignable to type 'Promise<string>'.\n\n// typedPool.all() will return a Promise<string[]>, typedPool.results() is an AsyncGenerator<string>\n\nconst relaxedPool = new AsyncPool();\n\nrelaxedPool.add({ task: async () => \"hello\" }); // OK\nrelaxedPool.add({ task: async () => 1 }); // OK\n\n// relaxedPool.all() will return a Promise<unknown[]>, relaxedPool.results() is an AsyncGenerator<unknown>\n```\n\n## API Documentation\n\n[API docs](./docs/globals.md)\n","readmeFilename":"Readme.md"}