{"id":20669041,"url":"https://github.com/jackchoumine/p-control","last_synced_at":"2026-02-09T17:36:22.117Z","repository":{"id":246862540,"uuid":"824420446","full_name":"jackchoumine/p-control","owner":"jackchoumine","description":"promise  concurrency control ","archived":false,"fork":false,"pushed_at":"2024-07-06T08:06:26.000Z","size":284,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-10T20:35:58.820Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/jackchoumine.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-07-05T05:24:20.000Z","updated_at":"2024-07-06T08:06:29.000Z","dependencies_parsed_at":"2025-06-25T20:05:24.501Z","dependency_job_id":"2567d4dc-7ffb-4394-a62f-6fb3a7386104","html_url":"https://github.com/jackchoumine/p-control","commit_stats":null,"previous_names":["jackchoumine/p-control"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jackchoumine/p-control","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackchoumine%2Fp-control","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackchoumine%2Fp-control/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackchoumine%2Fp-control/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackchoumine%2Fp-control/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jackchoumine","download_url":"https://codeload.github.com/jackchoumine/p-control/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackchoumine%2Fp-control/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29273791,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-09T17:15:22.002Z","status":"ssl_error","status_checked_at":"2026-02-09T17:14:42.395Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-11-16T20:12:40.767Z","updated_at":"2026-02-09T17:36:22.077Z","avatar_url":"https://github.com/jackchoumine.png","language":"TypeScript","readme":"# p-control\n\nPromise concurrency control.\n\nRun multiple async tasks with limited number in a easy way.\n\n\u003e Why you need this?\n\nWhen you have many asynchronous tasks, example for 100 http requests, you need to group them and execute them in concurrently group by group, it can help with well.\n\n## features\n\n- control async task by concurrent number\n- api is elegant and easy to use\n- promise and ts based\n- support browser and nodejs\n- very small size\n- MIT license\n\n## install\n\n```bash\nnpm install p-control\n```\n\n## usage\n\n### esm\n\n```js\nimport pControl from 'p-control';\n\n// control concurrent number，default is 6\n// because of browser limit http request number is 6 in one domain\nconst asyncControl = pControl(2)\n\nconst taskParams = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n\n// async task\nconst task = params =\u003e {\n  return new Promise(resolve =\u003e {\n    setTimeout(() =\u003e {\n      resolve(params)\n    }, 1000)\n  })\n}\n\n// add task to control with params firstly\ntaskParams.forEach(params =\u003e {\n  // add task params will be passed to task function\n  asyncControl.add(task, params)\n})\n// then start all tasks\nasyncControl\n  .start((res, doneSize) =\u003e {\n    // current concurrent tasks is done\n    // res is current concurrent tasks results\n    // doneSize is tasks finished size\n    // [{index:0, result: 1},{index:1, result: 2}] 2\n    // [{index:2, result: 3},{index:3, result: 4}] 4\n    // ...\n    console.log(res, doneSize)\n  })\n  .then(allTaskResults =\u003e {\n    // all tasks is done\n    console.log(allTaskResults) // [1,2,3,4,5,6,7,8,9,10]\n  })\n```\n\n### node commonjs\n\n```js\nconst pControl = require('p-control')\n// same as esm\n```\n\n### browser\n\n```html\n\u003c!-- umd --\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/p-control/dist/index.umd.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  const pControl = window.PControl // or PControl\n // same as before\n\u003c/script\u003e\n\u003c!-- esm  --\u003e\n\u003cscript type=\"module\"\u003e\n  import pControl from 'https://unpkg.com/p-control/dist/index.js';\n  // same as before\n\u003c/script\u003e\n```\n\n## API\n\n### `pControl(limit: number = 6): AsyncControl`\n\nCreate a async control instance with max concurrent limited number.\n\n### `AsyncControl`\n\nHave two methods:\n\n#### `add(task: Function, params: any): void`\n\nAdd a task to control with params.\n\n#### `start(concurrentDone?: (res: {index:number,result:any }[], doneSize: number) =\u003e void): Promise\u003cany[]\u003e`\n\nStart all tasks, `concurrentDone` will be called when current concurrent tasks is done.\n\n`concurrentDone` will be called with two arguments:\n\n- `res`: current concurrent tasks results, it's an array with object `{index: number, result: any}`, `index` is index of current task done and `result` is current async task result.\n- `doneSize`: tasks finished size.\n\nYou can use `res` to do something when current concurrent tasks is done, and `doneSize` to know how many tasks is done. You can calculate progress bar with `res` or `doneSize`.\n\nStart return a promise, when all tasks is done, promise will be resolved.\n\nYou can use `then` to get all tasks results.\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackchoumine%2Fp-control","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjackchoumine%2Fp-control","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackchoumine%2Fp-control/lists"}