{"_id":"bagpipe","_rev":"230910","name":"bagpipe","description":"Concurrency limit","dist-tags":{"latest":"0.3.5"},"maintainers":[{"name":"jacksontian","email":"shyvo1987@gmail.com"}],"time":{"modified":"2024-06-14T11:05:46.000Z","created":"2012-09-05T12:26:25.907Z","0.3.5":"2013-07-22T04:09:13.843Z","0.3.4":"2013-06-17T02:45:17.165Z","0.3.3":"2013-06-16T15:58:48.864Z","0.3.2":"2013-06-13T14:47:26.155Z","0.3.1":"2013-06-13T11:15:38.762Z","0.3.0":"2013-04-29T13:55:44.982Z","0.2.0":"2013-03-08T20:01:06.733Z","0.0.1":"2012-09-05T12:26:25.907Z"},"users":{"chinawolf_wyp":true,"hanhq":true,"arttse":true},"author":{"name":"Jackson Tian"},"repository":{"type":"git","url":"git://github.com/JacksonTian/bagpipe.git"},"versions":{"0.3.5":{"name":"bagpipe","version":"0.3.5","description":"Concurrency limit","keywords":["limiter","concurrency limit","parallel limit"],"main":"index.js","scripts":{"test":"make test-all","blanket":{"pattern":"bagpipe/lib"},"travis-cov":{"threshold":99}},"author":{"name":"Jackson Tian"},"license":"MIT","readmeFilename":"README.md","gitHead":"75269c60fdbb897be14575e70a2b86cf43999500","directories":{"doc":"doc","test":"test"},"devDependencies":{"pedding":"*","should":"*","blanket":"*","mocha":"*","travis-cov":"*"},"repository":{"type":"git","url":"git://github.com/JacksonTian/bagpipe.git"},"bugs":{"url":"https://github.com/JacksonTian/bagpipe/issues"},"_id":"bagpipe@0.3.5","dist":{"shasum":"e341d164fcb24cdf04ea7e05b765ec10c8aea6a1","tarball":"http://registry-npm.ywwl.com/bagpipe/download/bagpipe-0.3.5.tgz","integrity":"sha512-42sAlmPDKes1nLm/aly+0VdaopSU9br+jkRELedhQxI5uXHgtk47I83Mpmf4zoNTRMASdLFtUkimlu/Z9zQ8+g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDmEIpLBCNbgp7XrpBbSrZFpNOPxkEfEOGFbF8p6A9QTgIgLrKLhDrqmx7mN6c+dpoKys09LzJIgguDAduVZHRQM0w="}],"size":8357,"noattachment":false,"key":"/bagpipe/-/bagpipe-0.3.5.tgz"},"_from":".","_npmVersion":"1.2.32","_npmUser":{"name":"jacksontian","email":"shyvo1987@gmail.com"},"maintainers":[{"name":"jacksontian","email":"shyvo1987@gmail.com"}],"publish_time":1374466153843,"_cnpm_publish_time":1374466153843},"0.3.4":{"name":"bagpipe","version":"0.3.4","description":"Concurrency limit","keywords":["limiter","concurrency limit","parallel limit"],"main":"index.js","scripts":{"test":"make test-all","blanket":{"pattern":"bagpipe/lib"},"travis-cov":{"threshold":99}},"author":{"name":"Jackson Tian"},"license":"MIT","readmeFilename":"README.md","gitHead":"75269c60fdbb897be14575e70a2b86cf43999500","directories":{"doc":"doc","test":"test"},"devDependencies":{"pedding":"*","should":"*","blanket":"*","mocha":"*","travis-cov":"*"},"repository":{"type":"git","url":"git://github.com/JacksonTian/bagpipe.git"},"bugs":{"url":"https://github.com/JacksonTian/bagpipe/issues"},"_id":"bagpipe@0.3.4","dist":{"shasum":"292a6d103f0bc0b43cfb015e62190fcb19aed88f","tarball":"http://registry-npm.ywwl.com/bagpipe/download/bagpipe-0.3.4.tgz","integrity":"sha512-y4MpbHbv0Au4Y4J4XZjcvL5Yz/+Xxk033QdyDwD89OSgJKmJZKkonG+tKVVUnyH1QE3ecY9Me/vH6gGdQiEf9g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDXPpoilqecRWOpZt3SGy6VOY5v1+wGq6nhSFTEThm0AwIgU6SyNwyj+S5oe43jqCi51nHOiCXGPnxiBISeSbGdTbE="}],"size":8279,"noattachment":false,"key":"/bagpipe/-/bagpipe-0.3.4.tgz"},"_from":".","_npmVersion":"1.2.23","_npmUser":{"name":"jacksontian","email":"shyvo1987@gmail.com"},"maintainers":[{"name":"jacksontian","email":"shyvo1987@gmail.com"}],"publish_time":1371437117165,"_cnpm_publish_time":1371437117165},"0.3.3":{"name":"bagpipe","version":"0.3.3","description":"Concurrency limit","keywords":["limiter","concurrency limit","parallel limit"],"main":"index.js","scripts":{"test":"make test-all","blanket":{"pattern":"bagpipe/lib"},"travis-cov":{"threshold":99}},"author":{"name":"Jackson Tian"},"license":"MIT","readmeFilename":"README.md","gitHead":"75269c60fdbb897be14575e70a2b86cf43999500","directories":{"doc":"doc","test":"test"},"devDependencies":{"pedding":"*","should":"*","blanket":"*","mocha":"*","travis-cov":"*"},"repository":{"type":"git","url":"git://github.com/JacksonTian/bagpipe.git"},"bugs":{"url":"https://github.com/JacksonTian/bagpipe/issues"},"_id":"bagpipe@0.3.3","dist":{"shasum":"5be1c65032342b60e6fa0a57d19dff388a78d2c3","tarball":"http://registry-npm.ywwl.com/bagpipe/download/bagpipe-0.3.3.tgz","integrity":"sha512-Qp7zot2J3DYKeDK0+3r+4H9YQzRn9s+EZ1CIGIZQM7Mk8DPtD4wPkj9nsc1/TTjzpFyk0YVw545nJ0q7asZ+nw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDjphQFIO7gMYeleS5MPLMCHfysZFL5pC3DM/pqB0cNHgIgBnYLZ3/XHg5pOHof3pzuUBQUCcKM8oz3B6DKeS5XkxQ="}],"size":8200,"noattachment":false,"key":"/bagpipe/-/bagpipe-0.3.3.tgz"},"_from":".","_npmVersion":"1.2.23","_npmUser":{"name":"jacksontian","email":"shyvo1987@gmail.com"},"maintainers":[{"name":"jacksontian","email":"shyvo1987@gmail.com"}],"publish_time":1371398328864,"_cnpm_publish_time":1371398328864},"0.3.2":{"name":"bagpipe","version":"0.3.2","description":"Concurrency limit","keywords":["limiter","concurrency limit","parallel limit"],"main":"index.js","scripts":{"test":"make test-all","blanket":{"pattern":"bagpipe/lib"},"travis-cov":{"threshold":99}},"author":{"name":"Jackson Tian"},"license":"MIT","readmeFilename":"README.md","gitHead":"75269c60fdbb897be14575e70a2b86cf43999500","directories":{"doc":"doc","test":"test"},"devDependencies":{"pedding":"*","should":"*","blanket":"*","mocha":"*","travis-cov":"*"},"repository":{"type":"git","url":"git://github.com/JacksonTian/bagpipe.git"},"bugs":{"url":"https://github.com/JacksonTian/bagpipe/issues"},"_id":"bagpipe@0.3.2","dist":{"shasum":"14d55202e2b139f1fa7c5b0b2570ea6b21ec87b3","tarball":"http://registry-npm.ywwl.com/bagpipe/download/bagpipe-0.3.2.tgz","integrity":"sha512-aMUj2Y9Sm5NMt9ecBOyS1CI/elh71WJtcRldRip2zHO6ZK2cu8hXA5uGDuvbpFsE/yLPSzh73wxlue0aFh+/ug==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCVghWq6lrfP1hed8zs039ySDTAGy/nqijW3mkWF9ESegIhAPy0ubaG0IM4fPUubRpDkk1CYH5O6E64lrfR5Chnm4Gi"}],"size":7736,"noattachment":false,"key":"/bagpipe/-/bagpipe-0.3.2.tgz"},"_from":".","_npmVersion":"1.2.23","_npmUser":{"name":"jacksontian","email":"shyvo1987@gmail.com"},"maintainers":[{"name":"jacksontian","email":"shyvo1987@gmail.com"}],"publish_time":1371134846155,"_cnpm_publish_time":1371134846155},"0.3.1":{"name":"bagpipe","version":"0.3.1","description":"Concurrency limit","keywords":["limiter","concurrency limit","parallel limit"],"main":"index.js","scripts":{"test":"mocha -R spec"},"devDependencies":{"mocha":"*","should":"*","pedding":"*","jscover":"*"},"author":{"name":"Jackson Tian"},"license":"MIT","readmeFilename":"README.md","_id":"bagpipe@0.3.1","dist":{"shasum":"8ebe21720736a2fca8e0289592e919d07e91ae18","tarball":"http://registry-npm.ywwl.com/bagpipe/download/bagpipe-0.3.1.tgz","integrity":"sha512-emJX6bmbM0buciI1mOTkcw6hP9domFBz885ratt5FxuE2FGhoJHCd0NsugmWoshtEcncu8EoqU4vqOC5EczItQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICGE861/J/1oIe8pWCK5tYu26tAXhSfydMYyTLN4hh86AiA16DnPlxD7eGyR01lU0lfR3IOKUqObTCtFJjGFaQvk4Q=="}],"size":7279,"noattachment":false,"key":"/bagpipe/-/bagpipe-0.3.1.tgz"},"_from":".","_npmVersion":"1.2.23","_npmUser":{"name":"jacksontian","email":"shyvo1987@gmail.com"},"maintainers":[{"name":"jacksontian","email":"shyvo1987@gmail.com"}],"directories":{},"publish_time":1371122138762,"_cnpm_publish_time":1371122138762},"0.3.0":{"name":"bagpipe","version":"0.3.0","description":"bagpipe.js","keywords":["limiter","concurrency limit","parallel limit"],"main":"index.js","scripts":{"test":"mocha -R spec"},"devDependencies":{"mocha":"*","should":"*","pedding":"*","jscover":"*"},"author":{"name":"Jackson Tian"},"license":"MIT","readmeFilename":"README.md","_id":"bagpipe@0.3.0","dist":{"shasum":"a8a5cc25d73ef38929efa64198a997c9fcb9c1c3","tarball":"http://registry-npm.ywwl.com/bagpipe/download/bagpipe-0.3.0.tgz","integrity":"sha512-5WsZpCZrpgetis/ZjR7+nBqxztaWqvyZZJTq/mBYEVA6rjC9gEgyLi7VrXMpmLTFTwkKijKuoQN5im/anq5kpw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICA+GSU8qIqe+kKHIJU6mEGX5tEmgSe7dF7vkwo8FykCAiEA2xQAni4f7T01t8m44Fgp4FJMIPmQ8cQLm8H7xlIFxTw="}],"size":6911,"noattachment":false,"key":"/bagpipe/-/bagpipe-0.3.0.tgz"},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"jacksontian","email":"shyvo1987@gmail.com"},"maintainers":[{"name":"jacksontian","email":"shyvo1987@gmail.com"}],"directories":{},"publish_time":1367243744982,"_cnpm_publish_time":1367243744982},"0.2.0":{"name":"bagpipe","version":"0.2.0","description":"bagpipe.js","keywords":["limiter","concurrency limit","parallel limit"],"main":"index.js","scripts":{"test":"mocha -R spec"},"devDependencies":{"mocha":"*","should":"*"},"author":{"name":"Jackson Tian"},"license":"MIT","readmeFilename":"README.md","_id":"bagpipe@0.2.0","dist":{"shasum":"10a28627ba7a33a213dc242a30fed84696ce1296","tarball":"http://registry-npm.ywwl.com/bagpipe/download/bagpipe-0.2.0.tgz","integrity":"sha512-m8qiI8TIa98n+LsMOEcgYdp47XLnzKcBjCbU8zDKEo0w+3irrNnqw8DI6SMvLMywl1xjxCEM7hkUcSV05Pg6UQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDRemrETR6i086qoMy4sSz3yiCsKd1r3bn7nclJl+XX/wIgHTwsxgRndRGhu75CfKDSzmUVAa+XijdTEpGkMea1S68="}],"size":6515,"noattachment":false,"key":"/bagpipe/-/bagpipe-0.2.0.tgz"},"_from":".","_npmVersion":"1.2.2","_npmUser":{"name":"jacksontian","email":"shyvo1987@gmail.com"},"maintainers":[{"name":"jacksontian","email":"shyvo1987@gmail.com"}],"directories":{},"publish_time":1362772866733,"_cnpm_publish_time":1362772866733},"0.0.1":{"name":"bagpipe","version":"0.0.1","description":"bagpipe.js","main":"index.js","scripts":{"test":"mocha"},"author":{"name":"Jackson Tian"},"license":"MIT","_id":"bagpipe@0.0.1","dist":{"shasum":"b98668d19f188b3c9fca770e90746b1fb2a300b0","tarball":"http://registry-npm.ywwl.com/bagpipe/download/bagpipe-0.0.1.tgz","integrity":"sha512-MF4SFcNCvebENdg85bdxaVb7c6JLfKCsBWHznvjRXyDXGtgBCmTDwFYdSMYyq9oV8+hhKiqBkANbTjiSJLVJJA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCUj5NZQWCDDRhEAsqDU+9yhRHMHzPs89QpPt+NgK1S3QIgJSBaHR1qcn8rly6svsLIFVN2GSBQMmAeW/HfGPWm+ec="}],"size":715,"noattachment":false,"key":"/bagpipe/-/bagpipe-0.0.1.tgz"},"maintainers":[{"name":"jacksontian","email":"shyvo1987@gmail.com"}],"directories":{},"publish_time":1346847985907,"_cnpm_publish_time":1346847985907}},"readme":"Bagpipe [中文](https://github.com/JacksonTian/bagpipe/blob/master/README_CN.md)\n=======\nYou are the bagpiper.\n\n## Introduction\nIt is convenient for us to use asynchronism or concurrent to promote our business speed in Node. While, if the amount of concurrent is too large, our server may not support, such that we need to limit the amount of concurrent. Though, the http module contains [http.Agent](http://nodejs.org/docs/latest/api/http.html#http_class_http_agent) to control the amount of sockets, usually, our asynchronous API has packaged in advance. It is not realistic to change the inner API agent, let’s realize it on our own logical layer.\n\n## Installation\n```\nnpm install bagpipe\n```\n\n## API\nThe APIs exposed by Bagpipe only include constructor and instance methods `push`.\n\nUnder original status, we may execute concurrent like this, forming 100 concurrent asynchronous invokes.\n\n```\nfor (var i = 0; i < 100; i++) {\n  async(function () {\n    // Asynchronous call\n  });\n}\n```\nIf need to limit concurrency, what is your solution?\nSolution from Bagpipe as follows:\n\n```\nvar Bagpipe = require('bagpipe');\n// Sets the max concurrency as 100\nvar bagpipe = new Bagpipe(10);\nfor (var i = 0; i < 100; i++) {\n  bagpipe.push(async, function () {\n    // execute asynchronous callback\n  });\n}\n```\n\nYes, invoke method only splits method、parameter and callback, then delivery it to bagpipe through `push`.\n\nHow does it like compared with your anticipated solution?\n\n### Options\n\n- `refuse`, when queue is fulled, bagpipe will refuse the new async call and execute the callback with a `TooMuchAsyncCallError` exception. default `false`.\n- `timeout`, setting global ansyn call timeout. If async call doesn't complete in time, will execute the callback with `BagpipeTimeoutError` exception. default `null`.\n\n## Principles\nBagpipe delivers invoke into inner queue through `push`. If active invoke amount is less than max concurrent, it will be popped and executed directly, or it will stay in the queue. When an asynchronous invoke ends, a invoke in the head of the queue will be popped and executed, such that assures active asynchronous invoke amount no larger than restricted value.\n\nWhen the queue length is larger than 1, Bagpipe object will fire its `full` event, which delivers the queue length value. The value helps to assess business performance. For example:\n\n```\nbagpipe.on('full', function (length) {\n  console.warn('Button system cannot deal on time, queue jam, current queue length is:’+ length);\n});\n```\n\nIf queue length more than limit, you can set the `refuse` option to decide continue in queue or refuse call. The `refuse` default `false`. If set as `true`, the `TooMuchAsyncCallError` exception will pass to callback directly:\n\n```\nvar bagpipe = new BagPipe(10, {\n  refuse: true\n});\n```\n\nIf complete the async call is unexpected, the queue will not balanced. Set the timeout, let the callback executed with the `BagpipeTimeoutError` exception:\n\n```\nvar bagpipe = new BagPipe(10, {\n  timeout: 1000\n});\n```\n\n## Module status\nThe unit testing status: [![Build Status](https://secure.travis-ci.org/JacksonTian/bagpipe.png)](http://travis-ci.org/JacksonTian/bagpipe). Unit test coverage [100%](http://html5ify.com/bagpipe/coverage.html).\n\n## Best Practices\n- Ensure that the last parameter of the asynchronous invoke is callback.\n- Listen to the `full` event, adding your business performance assessment.\n- Current asynchronous method has not supported context yet. Ensure that there is no `this` reference in asynchronous method. If there is `this` reference in asynchronous method, please use `bind` pass into correct context.\n- Asynchronous invoke should process method to deal with timeout, it should ensure the invoke will return in a certain time no matter whether the business has been finished or not.\n\n## Real case\nWhen you want to traverse file directories, asynchrony can ensure `full` use of IO. You can invoke thousands of file reading easily. But, system file descriptors are limited. If disobedient, read this article again when occurring errors as follows.\n\n```\nError: EMFILE, too many open files\n```\n\nSomeone may consider dealing it with synchronous method. But, when synchronous, CPU and IO cannot be used concurrently, performance is an indefeasible index under certain condition. You can enjoy concurrent easily, as well as limit concurrent with Bagpipe.\n\n```\nvar bagpipe = new Bagpipe(10);\n\nvar files = ['Here are many files'];\nfor (var i = 0; i < files.length; i++) {\n  // fs.readFile(files[i], 'utf-8', function (err, data) {\n  bagpipe.push(fs.readFile, files[i], 'utf-8', function (err, data) {\n    // won’t occur error because of too many file descriptors\n    // well done\n  });\n}\n```\n\n## License\nReleased under the license of [MIT](https://github.com/JacksonTian/bagpipe/blob/master/MIT-License), welcome to enjoy open source.\n","_attachments":{},"readmeFilename":"README.md","bugs":{"url":"https://github.com/JacksonTian/bagpipe/issues"},"license":"MIT"}