{"id":17550622,"url":"https://github.com/imrandil/concurrent_promise_batcher_npm_package","last_synced_at":"2026-02-28T15:32:06.743Z","repository":{"id":239259077,"uuid":"799010944","full_name":"IMRANDIL/concurrent_promise_batcher_npm_package","owner":"IMRANDIL","description":"Concurrent Promise Batcher is a Node.js utility for executing asynchronous tasks concurrently in batches, providing better control over resource usage and improved performance.","archived":false,"fork":false,"pushed_at":"2024-05-11T09:26:41.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-30T02:58:46.210Z","etag":null,"topics":["batching","concurrency","nodejs","npm-package","promises"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@imrandil/concurrent-promise-batcher","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/IMRANDIL.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-11T00:24:56.000Z","updated_at":"2024-05-11T09:26:44.000Z","dependencies_parsed_at":"2024-05-11T03:33:48.112Z","dependency_job_id":"6dabf211-4908-4e8f-84c3-a9abe7c04462","html_url":"https://github.com/IMRANDIL/concurrent_promise_batcher_npm_package","commit_stats":null,"previous_names":["imrandil/concurrent_promise_batcher_npm_package"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/IMRANDIL/concurrent_promise_batcher_npm_package","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IMRANDIL%2Fconcurrent_promise_batcher_npm_package","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IMRANDIL%2Fconcurrent_promise_batcher_npm_package/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IMRANDIL%2Fconcurrent_promise_batcher_npm_package/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IMRANDIL%2Fconcurrent_promise_batcher_npm_package/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IMRANDIL","download_url":"https://codeload.github.com/IMRANDIL/concurrent_promise_batcher_npm_package/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IMRANDIL%2Fconcurrent_promise_batcher_npm_package/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284054333,"owners_count":26939559,"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","status":"online","status_checked_at":"2025-11-12T02:00:06.336Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["batching","concurrency","nodejs","npm-package","promises"],"created_at":"2024-10-21T04:06:02.696Z","updated_at":"2025-11-12T15:03:11.388Z","avatar_url":"https://github.com/IMRANDIL.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Concurrent Promise Batcher\n\nConcurrent Promise Batcher is a Node.js utility for executing asynchronous tasks concurrently in batches, providing better control over resource usage and improved performance. This package allows you to fetch data concurrently for multiple batches while managing the maximum number of concurrent promises being executed.\n\n## Installation\n\n```bash\nnpm install @imrandil/concurrent-promise-batcher\n```\n\n## Usage\n\n```javascript\nconst concurrentPromise = require('@imrandil/concurrent-promise-batcher');\n\n// Define a function to execute for each item in the batch\nasync function fetchData(item) {\n    // Perform asynchronous operation (e.g., fetching data from an API)\n    // Return a Promise\n}\n\n// Define your batches\nconst batches = [/* Array of items representing each batch */];\n\n// Set the maximum number of concurrent promises to execute\nconst batchConcurrency = 5;\n\n// Execute promises concurrently for batches\nconcurrentPromise(batchConcurrency, batches, fetchData)\n    .then((result) =\u003e {\n        console.log('Results:', result.results);\n        console.log('Execution Time:', result.executionTime);\n        console.log('Number of Batches Processed:', result.numBatchesProcessed);\n        console.log('Average Execution Time per Batch:', result.avgExecutionTimePerBatch);\n    })\n    .catch((error) =\u003e {\n        console.error('Error:', error.message);\n    });\n```\n\n### One of the use cases -\u003e\n\n```javascript\nconst concurrentPromise = require('@imrandil/concurrent-promise-batcher');\n\n// Function to fetch data from an API\nasync function fetchDataFromAPI(url) {\n    const response = await fetch(url);\n    return response.json();\n}\n\n// Array of API endpoints\nconst apiEndpoints = [\n    'https://hotels4.p.rapidapi.com/v2/get-meta-data',\n    'https://api.publicapis.org/entries',\n    'https://api.coindesk.com/v1/bpi/currentprice.json',\n    'https://www.boredapi.com/api/activity',\n    'https://dog.ceo/api/breeds/image/random'\n];\n\n// Define the maximum concurrency level\nconst maxConcurrency = 3; // For example, fetching data from 3 APIs concurrently\n\n// Fetch data concurrently from multiple APIs\nconcurrentPromise(maxConcurrency, apiEndpoints, fetchDataFromAPI, true)\n    .then(({ results, executionTime, numBatchesProcessed, avgExecutionTimePerBatch }) =\u003e {\n        console.log('Results:', results);\n        console.log('Execution time:', executionTime);\n        console.log('Number of batches processed:', numBatchesProcessed);\n        console.log('Average execution time per batch:', avgExecutionTimePerBatch);\n    })\n    .catch(error =\u003e {\n        console.error('Error:', error);\n    });\n\n```\n\n## Parameters\n\n- `batchConcurrency`: The maximum number of concurrent promises to execute. Must be a positive integer.\n- `batches`: An array of items representing each batch. Must be a non-empty array.\n- `fn`: The function to execute concurrently for each batch item. Must be a function.\n- `settled`: Whether to use `Promise.allSettled` or `Promise.all`. Default is `false` (`Promise.all`).\n\n## Examples\n\n- Fetching data from multiple APIs concurrently.\n- Processing multiple files concurrently.\n- Bulk operations on a database concurrently.\n\n## Using `Promise.all` vs `Promise.allSettled`\n\nBy default, `concurrentPromise` uses `Promise.all` to await the fulfillment of all promises in each batch. This means that if any promise rejects (encounters an error), the entire batch will fail and the rejection will be propagated to the caller.\n\nIf you want to handle individual promise rejections separately or continue processing even if some promises fail, you can set the `settled` parameter to `true`. This will make `concurrentPromise` use `Promise.allSettled` instead. With `Promise.allSettled`, the returned promise will fulfill with an array of objects representing the status of each promise, whether fulfilled or rejected.\n\n## License\n\n[MIT](https://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimrandil%2Fconcurrent_promise_batcher_npm_package","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimrandil%2Fconcurrent_promise_batcher_npm_package","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimrandil%2Fconcurrent_promise_batcher_npm_package/lists"}