{"_id":"p-control","_rev":"6-70d10dc8f3e3ef7c0030e556b22e13b9","name":"p-control","description":"promise concurrency control easy to use. async task control","dist-tags":{"latest":"1.1.3"},"versions":{"1.0.0":{"name":"p-control","version":"1.0.0","keywords":["promise control","promise limit","p control","p-limit","p-control","concurrency control","control","concurrency","task control","task concurrency","async task concurrency","async task control","tiny-tool","small-tool"],"author":{"name":"Jack Chou","email":"zhouqijun4job@163.com"},"license":"MIT","_id":"p-control@1.0.0","maintainers":[{"name":"zhou-qi-jun","email":"zhouqijun4job@163.com"}],"homepage":"https://github.com/jackchoumine/p-control?tab=readme-ov-file#p-control ","bugs":{"url":"https://github.com/jackchoumine/p-control/issues"},"dist":{"shasum":"7896b5fd0c89eb2ca559cc39c4e74b1435f0d3e7","tarball":"https://registry.npmjs.org/p-control/-/p-control-1.0.0.tgz","fileCount":12,"integrity":"sha512-DBhILRUCGigPl9hrfhs3IwpYEXdK1gUjJ6bpXgsfnonq7DBKg0YCnzJVq3UrzNHoFSJNGJ1J6UeaFg2tS8quqg==","signatures":[{"sig":"MEYCIQCvxATaRJ/70bFKVeq0IwO0fq97jn0Z+hPHFRTxCTb2rQIhALkaMJZc3Di25dY738AKK3EAH90amP7uIOBgHW95V+Kx","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":17692},"main":"./dist/index.cjs","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.js","source":"src/pControl.ts","amdName":"PC","exports":{".":{"import":"./dist/index.js","default":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"2fc9ee18fa7668b4c92c2ec2e017debca1c791b0","private":false,"scripts":{"build":"microbundle"},"_npmUser":{"name":"zhou-qi-jun","email":"zhouqijun4job@163.com"},"repository":{"url":"git+https://github.com/jackchoumine/p-control.git","type":"git"},"_npmVersion":"10.2.4","description":"promise concurrency control easy to use. async task control","directories":{},"_nodeVersion":"18.19.1","_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.5.3","microbundle":"^0.15.1"},"_npmOperationalInternal":{"tmp":"tmp/p-control_1.0.0_1720164975773_0.7939121963291229","host":"s3://npm-registry-packages"}},"1.0.1":{"name":"p-control","version":"1.0.1","keywords":["promise control","promise limit","p control","p-limit","p-control","concurrency control","control","concurrency","task control","task concurrency","async task concurrency","async task control","tiny-tool","small-tool"],"author":{"name":"Jack Chou","email":"zhouqijun4job@163.com"},"license":"MIT","_id":"p-control@1.0.1","maintainers":[{"name":"zhou-qi-jun","email":"zhouqijun4job@163.com"}],"homepage":"https://github.com/jackchoumine/p-control?tab=readme-ov-file#p-control ","bugs":{"url":"https://github.com/jackchoumine/p-control/issues"},"dist":{"shasum":"e7f292b224417fb5463019198567f3ff53986579","tarball":"https://registry.npmjs.org/p-control/-/p-control-1.0.1.tgz","fileCount":12,"integrity":"sha512-a4d6DeaR0QUF9IRmK2aZaFGvYCOtR9Hc6ETgOra1h4x0iqaG0EO6NchaUiMIEVKAufsyFfxEx7SGiHh9GBSNtA==","signatures":[{"sig":"MEUCIQCKkK6Ka1S0EBGg5UYT8v6KTgCTIaW3sCV26/6AI7A3zAIgEHfXuLZbdT5iFTJe3ob24/inGIpsdAMtciM9S38wZuQ=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":17870},"main":"dist/index.cjs","type":"module","types":"dist/pControl.d.ts","unpkg":"dist/index.umd.js","module":"dist/index.js","source":"src/pControl.ts","amdName":"PC","exports":{".":{"import":"./dist/index.js","default":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"a87154a16154dd1aae02a3af02ad2d2445b22215","private":false,"scripts":{"build":"microbundle"},"_npmUser":{"name":"zhou-qi-jun","email":"zhouqijun4job@163.com"},"repository":{"url":"git+https://github.com/jackchoumine/p-control.git","type":"git"},"_npmVersion":"10.2.4","description":"promise concurrency control easy to use. async task control","directories":{},"_nodeVersion":"18.19.1","_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.5.3","microbundle":"^0.15.1"},"_npmOperationalInternal":{"tmp":"tmp/p-control_1.0.1_1720168176311_0.38927738094890896","host":"s3://npm-registry-packages"}},"1.0.2":{"name":"p-control","version":"1.0.2","keywords":["promise control","promise limit","p control","p-limit","p-control","concurrency control","control","concurrency","task control","task concurrency","async task concurrency","async task control","tiny-tool","small-tool"],"author":{"name":"Jack Chou","email":"zhouqijun4job@163.com"},"license":"MIT","_id":"p-control@1.0.2","maintainers":[{"name":"zhou-qi-jun","email":"zhouqijun4job@163.com"}],"homepage":"https://github.com/jackchoumine/p-control?tab=readme-ov-file#p-control ","bugs":{"url":"https://github.com/jackchoumine/p-control/issues"},"dist":{"shasum":"11433ea7d5381e9ebd53e8bdf87fa52eaf2a7bf4","tarball":"https://registry.npmjs.org/p-control/-/p-control-1.0.2.tgz","fileCount":12,"integrity":"sha512-Mcj6z/KX5s7i085nWJ+TEA43CNRQCIQ5gtisjIMuYkQ0tLhfXpEMUiw5UYx4hTL3OuE3u9M9KaV/X/q+ZGW7Vg==","signatures":[{"sig":"MEQCICQGX6rLXIryfrZEdMRsjLKXFJ/0febyS2tLk4uInmn/AiBy1gAF7DDSMn5bKtT0nZm6KllXlJtm16VGtnbvpNAAHg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":19084},"main":"dist/index.cjs","type":"module","types":"dist/pControl.d.ts","unpkg":"dist/index.umd.js","module":"dist/index.js","source":"src/pControl.ts","amdName":"PControl","exports":{".":{"import":"./dist/index.js","default":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"6bf49ea155c4253fbc6be9828be35a2e6c95ce42","private":false,"scripts":{"build":"microbundle"},"_npmUser":{"name":"zhou-qi-jun","email":"zhouqijun4job@163.com"},"repository":{"url":"git+https://github.com/jackchoumine/p-control.git","type":"git"},"_npmVersion":"10.2.4","description":"promise concurrency control easy to use. async task control","directories":{},"_nodeVersion":"18.19.1","_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.5.3","microbundle":"^0.15.1"},"_npmOperationalInternal":{"tmp":"tmp/p-control_1.0.2_1720249440600_0.7889262427387875","host":"s3://npm-registry-packages"}},"1.1.0":{"name":"p-control","version":"1.1.0","keywords":["promise control","promise limit","p control","p-limit","p-control","concurrency control","control","concurrency","task control","task concurrency","async task concurrency","async task control","tiny-tool","small-tool"],"author":{"name":"Jack Chou","email":"zhouqijun4job@163.com"},"license":"MIT","_id":"p-control@1.1.0","maintainers":[{"name":"zhou-qi-jun","email":"zhouqijun4job@163.com"}],"homepage":"https://github.com/jackchoumine/p-control?tab=readme-ov-file#p-control ","bugs":{"url":"https://github.com/jackchoumine/p-control/issues"},"dist":{"shasum":"2c537770b1e0bd39b4caeae89dfcc08f18cdd306","tarball":"https://registry.npmjs.org/p-control/-/p-control-1.1.0.tgz","fileCount":12,"integrity":"sha512-hHW5IFX3RCXaWcnj7SyrsZ5uWi5BU2Qou7P7KW4hS5BhRZubvmeWSmTlqyvH6pCQnKr69bNUHneOVEpl6o974Q==","signatures":[{"sig":"MEQCIHa8PvIZnymOs/+lGgLytrHM0AyNzrc1FPPWGGHhXyUOAiA0aQB2LBURw5aFY7nHS/1o1Hbr8vPD0xCuwKMsi6/4rA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":23710},"main":"dist/index.cjs","type":"module","types":"dist/pControl.d.ts","unpkg":"dist/index.umd.js","module":"dist/index.js","source":"src/pControl.ts","amdName":"PControl","exports":{".":{"import":"./dist/index.js","default":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"2a3ea7f65841bbf8918a0e336bea21996531c95c","private":false,"scripts":{"build":"microbundle"},"_npmUser":{"name":"zhou-qi-jun","email":"zhouqijun4job@163.com"},"repository":{"url":"git+https://github.com/jackchoumine/p-control.git","type":"git"},"_npmVersion":"10.2.4","description":"promise concurrency control easy to use. async task control","directories":{},"_nodeVersion":"18.19.1","_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.5.3","microbundle":"^0.15.1"},"_npmOperationalInternal":{"tmp":"tmp/p-control_1.1.0_1720252166824_0.5324672198255589","host":"s3://npm-registry-packages"}},"1.1.1":{"name":"p-control","version":"1.1.1","keywords":["promise control","promise limit","p control","p-limit","p-control","concurrency control","control","concurrency","task control","task concurrency","async task concurrency","async task control","tiny-tool","small-tool"],"author":{"name":"Jack Chou","email":"zhouqijun4job@163.com"},"license":"MIT","_id":"p-control@1.1.1","maintainers":[{"name":"zhou-qi-jun","email":"zhouqijun4job@163.com"}],"homepage":"https://github.com/jackchoumine/p-control?tab=readme-ov-file#p-control ","bugs":{"url":"https://github.com/jackchoumine/p-control/issues"},"dist":{"shasum":"8889080ded8e27e47f6393d9b49d3bf6424487d5","tarball":"https://registry.npmjs.org/p-control/-/p-control-1.1.1.tgz","fileCount":12,"integrity":"sha512-SzYf4EF4sK1MiBC5xjp8dprlBrWal9r42rfrddpQke+oLLr7ZJYKmwt92GhefjHyrHMyVtCCLcOIXsO6URmz4A==","signatures":[{"sig":"MEYCIQCm25Qqo5y7yLYb/kI5U+2RH2vw+R+7NgZ3MBl98k6j0QIhAOZn9sRzCPYvwdDKycO6Bp0Lrlr3nb4tH635yeSfG/tn","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":23717},"main":"dist/index.cjs","type":"module","types":"dist/pControl.d.ts","unpkg":"dist/index.umd.js","module":"dist/index.js","source":"src/pControl.ts","amdName":"PControl","exports":{".":{"import":"./dist/index.js","default":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"7c45fda7ce21b74883ee8f739ccecf5906d76018","private":false,"scripts":{"build":"microbundle"},"_npmUser":{"name":"zhou-qi-jun","email":"zhouqijun4job@163.com"},"repository":{"url":"git+https://github.com/jackchoumine/p-control.git","type":"git"},"_npmVersion":"10.2.4","description":"promise concurrency control easy to use. async task control","directories":{},"_nodeVersion":"18.19.1","_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.5.3","microbundle":"^0.15.1"},"_npmOperationalInternal":{"tmp":"tmp/p-control_1.1.1_1720252396515_0.412407659888693","host":"s3://npm-registry-packages"}},"1.1.2":{"name":"p-control","version":"1.1.2","keywords":["promise control","promise limit","p control","p-limit","p-control","concurrency control","control","concurrency","task control","task concurrency","async task concurrency","async task control","tiny-tool","small-tool"],"author":{"name":"Jack Chou","email":"zhouqijun4job@163.com"},"license":"MIT","_id":"p-control@1.1.2","maintainers":[{"name":"zhou-qi-jun","email":"zhouqijun4job@163.com"}],"homepage":"https://github.com/jackchoumine/p-control?tab=readme-ov-file#p-control ","bugs":{"url":"https://github.com/jackchoumine/p-control/issues"},"dist":{"shasum":"8999dc2aabae36b8d5123c76f29b20637840899a","tarball":"https://registry.npmjs.org/p-control/-/p-control-1.1.2.tgz","fileCount":12,"integrity":"sha512-CJKCWG/HN+lPjNX6AsddYvnUKVgnP0HDgObLAAxOJGNJS7TVn+ip6Q0d/31hh/nAdOwvdfJOFVOLdBQNmr1q2g==","signatures":[{"sig":"MEUCIQDffJ26Uduv5FfkQcZyKfjQSb2gHruNkuTyvDjaA9loWwIgNRP019QoJ7YzZCWp1KKavc9EnxgOD1Y7QQ3zDWZVTyA=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":23717},"main":"dist/index.cjs","type":"module","types":"dist/pControl.d.ts","unpkg":"dist/index.umd.js","module":"dist/index.js","source":"src/pControl.ts","amdName":"PControl","exports":{".":{"import":"./dist/index.js","default":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"707db625e5d2666aa3625e78808e48925c7756c3","private":false,"scripts":{"build":"microbundle"},"_npmUser":{"name":"zhou-qi-jun","email":"zhouqijun4job@163.com"},"repository":{"url":"git+https://github.com/jackchoumine/p-control.git","type":"git"},"_npmVersion":"10.2.4","description":"promise concurrency control easy to use. async task control","directories":{},"_nodeVersion":"18.19.1","_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.5.3","microbundle":"^0.15.1"},"_npmOperationalInternal":{"tmp":"tmp/p-control_1.1.2_1720253022562_0.3586125504196309","host":"s3://npm-registry-packages"}},"1.1.3":{"name":"p-control","version":"1.1.3","description":"promise concurrency control easy to use. async task control","private":false,"type":"module","source":"src/pControl.ts","amdName":"PControl","main":"dist/index.cjs","module":"dist/index.js","unpkg":"dist/index.umd.js","types":"dist/pControl.d.ts","exports":{".":{"import":"./dist/index.js","require":"./dist/index.cjs","default":"./dist/index.js"}},"scripts":{"build":"microbundle"},"keywords":["promise control","promise limit","p control","p-limit","p-control","concurrency control","control","concurrency","task control","task concurrency","async task concurrency","async task control","tiny-tool","small-tool"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/jackchoumine/p-control.git"},"homepage":"https://github.com/jackchoumine/p-control?tab=readme-ov-file#p-control ","author":{"name":"Jack Chou","email":"zhouqijun4job@163.com"},"devDependencies":{"microbundle":"^0.15.1","typescript":"^5.5.3"},"_id":"p-control@1.1.3","gitHead":"b37bec695ef3d2d16dc5e6df27c9441756ba7a89","bugs":{"url":"https://github.com/jackchoumine/p-control/issues"},"_nodeVersion":"18.19.1","_npmVersion":"10.2.4","dist":{"integrity":"sha512-eY1ew828qr01+CtYsdaYBCxsa+6yoYdSI8xj8q7ZIJ9jth7UOMGfFQya9QCGkfYBb7Cl51VVF9o+G/sdiG6ARA==","shasum":"bfc27b737e0e1d9880aec405021d4cbf518db5cf","tarball":"https://registry.npmjs.org/p-control/-/p-control-1.1.3.tgz","fileCount":12,"unpackedSize":23718,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDQqh7TAZ+8kcieBT/a8EHjppnN7u640p8mzvSO9E0/1gIhAIA3j29U5PC3WW/1acIqON+kPiGkYedg5yqRpjcavMS7"}]},"_npmUser":{"name":"zhou-qi-jun","email":"zhouqijun4job@163.com"},"directories":{},"maintainers":[{"name":"zhou-qi-jun","email":"zhouqijun4job@163.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-control_1.1.3_1720253181070_0.26649192097137897"},"_hasShrinkwrap":false}},"time":{"created":"2024-07-05T07:36:15.772Z","modified":"2024-07-06T08:06:21.423Z","1.0.0":"2024-07-05T07:36:15.949Z","1.0.1":"2024-07-05T08:29:36.464Z","1.0.2":"2024-07-06T07:04:00.720Z","1.1.0":"2024-07-06T07:49:26.962Z","1.1.1":"2024-07-06T07:53:16.671Z","1.1.2":"2024-07-06T08:03:42.681Z","1.1.3":"2024-07-06T08:06:21.217Z"},"maintainers":[{"name":"zhou-qi-jun","email":"zhouqijun4job@163.com"}],"author":{"name":"Jack Chou","email":"zhouqijun4job@163.com"},"repository":{"type":"git","url":"git+https://github.com/jackchoumine/p-control.git"},"keywords":["promise control","promise limit","p control","p-limit","p-control","concurrency control","control","concurrency","task control","task concurrency","async task concurrency","async task control","tiny-tool","small-tool"],"license":"MIT","homepage":"https://github.com/jackchoumine/p-control?tab=readme-ov-file#p-control ","bugs":{"url":"https://github.com/jackchoumine/p-control/issues"},"readme":"# p-control\r\n\r\nPromise concurrency control.\r\n\r\nRun multiple async tasks with limited number in a easy way.\r\n\r\n> Why you need this?\r\n\r\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.\r\n\r\n## features\r\n\r\n- control async task by concurrent number\r\n- api is elegant and easy to use\r\n- promise and ts based\r\n- support browser and nodejs\r\n- very small size\r\n- MIT license\r\n\r\n## install\r\n\r\n```bash\r\nnpm install p-control\r\n```\r\n\r\n## usage\r\n\r\n### esm\r\n\r\n```js\r\nimport pControl from 'p-control';\r\n\r\n// control concurrent number，default is 6\r\n// because of browser limit http request number is 6 in one domain\r\nconst asyncControl = pControl(2)\r\n\r\nconst taskParams = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\r\n\r\n// async task\r\nconst task = params => {\r\n  return new Promise(resolve => {\r\n    setTimeout(() => {\r\n      resolve(params)\r\n    }, 1000)\r\n  })\r\n}\r\n\r\n// add task to control with params firstly\r\ntaskParams.forEach(params => {\r\n  // add task params will be passed to task function\r\n  asyncControl.add(task, params)\r\n})\r\n// then start all tasks\r\nasyncControl\r\n  .start((res, doneSize) => {\r\n    // current concurrent tasks is done\r\n    // res is current concurrent tasks results\r\n    // doneSize is tasks finished size\r\n    // [{index:0, result: 1},{index:1, result: 2}] 2\r\n    // [{index:2, result: 3},{index:3, result: 4}] 4\r\n    // ...\r\n    console.log(res, doneSize)\r\n  })\r\n  .then(allTaskResults => {\r\n    // all tasks is done\r\n    console.log(allTaskResults) // [1,2,3,4,5,6,7,8,9,10]\r\n  })\r\n```\r\n\r\n### node commonjs\r\n\r\n```js\r\nconst pControl = require('p-control')\r\n// same as esm\r\n```\r\n\r\n### browser\r\n\r\n```html\r\n<!-- umd -->\r\n<script src=\"https://cdn.jsdelivr.net/npm/p-control/dist/index.umd.js\"></script>\r\n<script>\r\n  const pControl = window.PControl // or PControl\r\n // same as before\r\n</script>\r\n<!-- esm  -->\r\n<script type=\"module\">\r\n  import pControl from 'https://unpkg.com/p-control/dist/index.js';\r\n  // same as before\r\n</script>\r\n```\r\n\r\n## API\r\n\r\n### `pControl(limit: number = 6): AsyncControl`\r\n\r\nCreate a async control instance with max concurrent limited number.\r\n\r\n### `AsyncControl`\r\n\r\nHave two methods:\r\n\r\n#### `add(task: Function, params: any): void`\r\n\r\nAdd a task to control with params.\r\n\r\n#### `start(concurrentDone?: (res: {index:number,result:any }[], doneSize: number) => void): Promise<any[]>`\r\n\r\nStart all tasks, `concurrentDone` will be called when current concurrent tasks is done.\r\n\r\n`concurrentDone` will be called with two arguments:\r\n\r\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.\r\n- `doneSize`: tasks finished size.\r\n\r\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`.\r\n\r\nStart return a promise, when all tasks is done, promise will be resolved.\r\n\r\nYou can use `then` to get all tasks results.\r\n\r\n## License\r\n\r\nMIT\r\n","readmeFilename":"README.md"}