{"id":17259089,"url":"https://github.com/notanengineercom/simple-async-pool","last_synced_at":"2025-09-01T10:06:57.358Z","repository":{"id":57359771,"uuid":"336647850","full_name":"notanengineercom/simple-async-pool","owner":"notanengineercom","description":"Easy to use, dependency free and typesafe concurrent pool of async and promise returning functions","archived":false,"fork":false,"pushed_at":"2024-03-19T20:49:10.000Z","size":78,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T19:54:33.301Z","etag":null,"topics":["async","concurrency","dependecy-free","iterator","no-dependencies","nodejs","pool","promise","typesafe","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/simple-async-pool","language":"TypeScript","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/notanengineercom.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":"2021-02-06T22:13:52.000Z","updated_at":"2024-02-26T21:58:10.000Z","dependencies_parsed_at":"2022-09-06T21:41:19.462Z","dependency_job_id":null,"html_url":"https://github.com/notanengineercom/simple-async-pool","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notanengineercom%2Fsimple-async-pool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notanengineercom%2Fsimple-async-pool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notanengineercom%2Fsimple-async-pool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notanengineercom%2Fsimple-async-pool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/notanengineercom","download_url":"https://codeload.github.com/notanengineercom/simple-async-pool/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248830395,"owners_count":21168272,"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":["async","concurrency","dependecy-free","iterator","no-dependencies","nodejs","pool","promise","typesafe","typescript"],"created_at":"2024-10-15T07:23:09.899Z","updated_at":"2025-09-01T10:06:57.344Z","avatar_url":"https://github.com/notanengineercom.png","language":"TypeScript","readme":"# simple-async-pool\n[![npm:version](https://flat.badgen.net/npm/license/simple-async-pool?icon=npm)](https://www.npmjs.com/package/simple-async-pool)\n[![npm:version](https://flat.badgen.net/npm/v/simple-async-pool?icon=npm)](https://www.npmjs.com/package/simple-async-pool)\n[![packagephobia](https://flat.badgen.net/packagephobia/install/simple-async-pool)](https://packagephobia.com/result?p=simple-async-pool)\n[![ci](https://flat.badgen.net/github/checks/notanengineercom/simple-async-pool/main?icon=github)](https://github.com/notanengineercom/simple-async-pool/actions)\n\nEasy to use, dependency free and typesafe concurrent pool of async and promise returning functions.\n\n## Installation\n\n```sh\nnpm i simple-async-pool\n```\n\n## Usage\nUsing the async pool is really simple. The package exposes a `pool` function with the following simplified signature:\n```ts\nfunction pool(options: PoolOptions, consumerFunction, ...input)\nfunction pool(consumerFunction, ...input)\n```\n\n\nThe `PoolOptions` interface has the following members:\n```ts\ninterface PoolOptions {\n  output?: 'AsyncIterator' | 'Promise' // defines the return value of the pool function ('Promise' by default)\n  concurrency?: number // defines the number of concurrent workers to spawn (1 by default)\n}\n```\n\n\nBy default, when no pool options are provided, the pool function returns a promise that resolves the processed input values with a concurrency of one:\n```ts\nimport { pool } from 'simple-async-pool'\n\nconst consumerFunction = async (input: string) =\u003e input\nconst processedValues = await pool(consumerFunction, 'simple', 'async', 'pool') // if the input values are not strings, typescript complains due to the type missmatch\n\nconsole.log(processedValues) // [ 'simple', 'async', 'pool' ]\n```\n\nThe input values can either be an array (spread syntax), an iterator, an async iterator or a generator function (async/non async).\n```ts\nconst processedValues = await pool(consumerFunction, 'simple', 'async', 'pool')\n\n// ...\n\nconst input = ['simple', 'async', 'pool']\nconst processedValues = await pool(consumerFunction, input.values())\n\n// ...\n\nfunction* input() {\n  yield 'simple'\n  yield 'async'\n  yield 'pool'\n}\nconst processedValues = await pool(consumerFunction, input())\n\n// ...\n\nasync function* input() {\n  yield 'simple'\n  yield 'async'\n  yield 'pool'\n}\nconst processedValues = await pool(consumerFunction, input())\n\nconsole.log(processedValues) // [ 'simple', 'async', 'pool' ]\n\n// ...\n\nfunction* input() {\n  yield 'simple'\n  yield 'async'\n  yield 'pool'\n}\nconst processedValues = await pool(consumerFunction, input)\n\n// ...\n\nasync function* input() {\n  yield 'simple'\n  yield 'async'\n  yield 'pool'\n}\nconst processedValues = await pool(consumerFunction, input)\n\nconsole.log(processedValues) // [ 'simple', 'async', 'pool' ]\n```\n\nTo modify the default behaviour, pool options can be provided as an argument:\n```ts\nconst processedValues = await pool({ concurrency: 3 }, consumerFunction, 'simple', 'async', 'pool')\nconsole.log(processedValues) // [ 'simple', 'async', 'pool' ]\n```\n\n\nReturning an async iterator instead of a promise can be achieved via the pool options too:\n```ts\nconst iterator = pool({ concurrency: 3, output: 'AsyncIterator' }, consumerFunction, 'simple', 'async', 'pool')\n\nconst values = []\nfor await (const value of iterator) values.push(value)\n```\n\n\nWhen the `output` property in the options is set to `Promise` (default behaviour), the order of the output values is guaranteed.\nWhen it's `AsyncIterator`, values are yielded in the order of resolution, so no order can be guaranteed.\n\n\n## License\n\nMIT © **Enrique Pöhlmann**\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotanengineercom%2Fsimple-async-pool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnotanengineercom%2Fsimple-async-pool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotanengineercom%2Fsimple-async-pool/lists"}