{"id":26197661,"url":"https://github.com/eetay/promise-pool-js","last_synced_at":"2025-04-15T04:26:00.307Z","repository":{"id":32696096,"uuid":"140195653","full_name":"eetay/promise-pool-js","owner":"eetay","description":"Library to execute promises in parallel, keeping not to execute more than N promises at any one time","archived":false,"fork":false,"pushed_at":"2023-01-05T02:34:43.000Z","size":895,"stargazers_count":5,"open_issues_count":15,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-25T00:56:17.909Z","etag":null,"topics":["node","node-module","promise-queue","promises"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eetay.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-08T19:15:45.000Z","updated_at":"2022-04-26T03:02:35.000Z","dependencies_parsed_at":"2023-01-14T21:57:36.187Z","dependency_job_id":null,"html_url":"https://github.com/eetay/promise-pool-js","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eetay%2Fpromise-pool-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eetay%2Fpromise-pool-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eetay%2Fpromise-pool-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eetay%2Fpromise-pool-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eetay","download_url":"https://codeload.github.com/eetay/promise-pool-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249005357,"owners_count":21197045,"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":["node","node-module","promise-queue","promises"],"created_at":"2025-03-12T02:48:22.264Z","updated_at":"2025-04-15T04:26:00.286Z","avatar_url":"https://github.com/eetay.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tiny Promise Pool\nA tiny library to execute multiple promises in parallel,\nkeeping not to execute more than N promises at any one time,\nusing a promise.\n\n- Tiny Promise Pool is reviewed by [![Codacy Badge](https://api.codacy.com/project/badge/Grade/6ba3a2ddf94b42a1b28de6020117b33d)](https://www.codacy.com/app/eetay/promise-pool-js?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=eetay/promise-pool-js\u0026amp;utm_campaign=Badge_Grade)\n- Tiny promise Pool is unit tested with \u003cimg src=\"./spec/jest.png\" alt=\"Jest\" width=\"32px\"/\u003e\n\n## Install:\n\n```bash\nnpm i tiny-promise-pool\n```\n\n\n## Use with creator function:\n\n```javascript\nvar promisePool = require('tiny-promise-pool')\n\nfunction nextPromise({index, data}) {\n  if (index\u003e=20) return null // no more\n  return new Promise(function(res, rej) {\n    res(index*2 + data)\n  })\n}\n\nvar all = promisePool({\n  threads: 3,                 // maximum parallel promises\n  promises: nextPromise,  // function to get/generate next promise\n  context_data: 17       // user data for the next_promise function\n})\n\nall.then(function(result) {\n  console.dir(result)         // after all promises are resolved\n})\n```\n\n### Result:\n\n```javascript\n[\n  { context: { index: 0, thread: 0, data: 17, ended: 10 }, promise: Promise { 17 }, result: 17 },\n  { context: { index: 1, thread: 1, data: 17, ended: 1 }, promise: Promise { 19 }, result: 19 },\n  { context: { index: 2, thread: 2, data: 17, ended: 7 }, promise: Promise { 21 }, result: 21 },\n  { context: { index: 3, thread: 0, data: 17, ended: 6 }, promise: Promise { 23 }, result: 23 },\n  { context: { index: 4, thread: 1, data: 17, ended: 2 }, promise: Promise { 25 }, result: 25 },\n  { context: { index: 5, thread: 2, data: 17, ended: 3 }, promise: Promise { 27 }, result: 27 },\n  { context: { index: 6, thread: 0, data: 17, ended: 4 }, promise: Promise { 29 }, result: 29 },\n  { context: { index: 7, thread: 1, data: 17, ended: 5 }, promise: Promise { 31 }, result: 31 },\n  ...\n  { context: { index: 19, thread: 1, data: 17, ended: 19 }, promise: Promise { 55 }, result: 55 }\n]\n```\n\n## Use with array of promises:\n\n```javascript\nfunction makePromise(i) {\n  return new Promise(function (resolve, _reject) {\n    resolve(i)\n  })\n}\n\nconst promiseList = [\n  makePromise(0),\n  makePromise(1)\n]\n\npromisePool({\n  threads: 3,\n  promises: promiseList,              // List of promises\n  context_data: 'data for context'\n}).then(function(result) {\n  ...\n})\n```\n\n## Using generator to generate promises:\n\n```javascript\nfunction *createPromiseMaker() {\n  for (var i=0; i\u003c10; i+=1) {\n    yield new Promise(...)\n  }\n}\n\nconst pool = promisePool({\n  threads: 3,\n  promises: createPromiseMaker()\n})\n```\n\n## Nested promise pools:\n\n```javascript\nconst innerPool = promisePool({\n  threads: 2,\n  promises: [\n    makePromise(2),\n    makePromise(3),\n    makePromise(4),\n    makePromise(5)\n  ],\n  context_data: 'secondary promise pool'\n})\nconst pool = promisePool({\n  threads: 3,\n  promises: [\n    makePromise(0),\n    makePromise(1),\n    innerPool\n  ],\n  context_data: 'primary promise pool'\n})\npool.then(function(result) {\n  ...\n}\n```\n\n## Debugging tool:\n\n```javascript\npromisePool = require('tiny-promise-pool')\nvisualize = require('tiny-promise-pool/promise-pool-visualize')\nconst pool = promisePool({\n  ...\n})\npool.then(visualize).then(result =\u003e {\n   ...\n})\n```\n\n## TODO list:\n- API similar to Promise.all(): \"Promise.pool([promise, ...], threads)\"\n- options for behavior on reject:\n  - reject as soon as one is rejected (same as Promise.all)\n  - wait for all to resolve even if some are rejected (same as Promise.when)\n- support listeners for individual promise completions/rejections\n\n## migration from previous versions:\nthe following option keys are renamed:\n1. next_promise_data -\u003e context_data\n2. next_promise -\u003e promises\n2. max_parallel -\u003e threads\n\nyou can still use the older option keys, but they are deprecated\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feetay%2Fpromise-pool-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feetay%2Fpromise-pool-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feetay%2Fpromise-pool-js/lists"}