bower
Version:
The browser package manager
46 lines (45 loc) • 3.51 kB
JSON
{
"name": "p-throttler",
"version": "0.1.1",
"description": "A promise based throttler capable of limiting execution of parallel tasks",
"main": "index.js",
"dependencies": {
"q": "~0.9.2"
},
"devDependencies": {
"mocha": "~1.10.0",
"expect.js": "~0.2.0"
},
"scripts": {
"test": "mocha -R spec"
},
"repository": {
"type": "git",
"url": "git://github.com/IndigoUnited/node-p-throttler.git"
},
"bugs": {
"url": "http://github.com/IndigoUnited/node-p-throttler/issues"
},
"keywords": [
"promise",
"throttler",
"trottle",
"deferred",
"worker",
"tasks",
"parallel"
],
"author": {
"name": "IndigoUnited",
"email": "hello@indigounited.com",
"url": "http://indigounited.com"
},
"license": "MIT",
"readme": "# p-throttler [](http://travis-ci.org/IndigoUnited/node-p-throttler.png)\n\nA promise based throttler responsible for limiting execution of parallel tasks.\nThe number of parallel tasks may be limited and configured per type.\n\n\n## Installation\n\n`$ npm install p-throttler`\n\n\n## API\n\n### #create(defaultConcurrency, types)\n\nConstructs a new throttler.\n\nThe `defaultConcurrency` is the default maximum concurrent functions being run (-1 to specify no limits). \nThe `types` allows you to specify different concurrencies for different types. \n\nExample:\n\n```js\nvar throttler = PThrottler.create(15, { // or new PThrottler()\n 'network_io': 10,\n 'disk_io': 50\n});\n```\n\n\n### .enqueue(func, [type]): Promise\n\nEnqueues a function to be ran. The function is expected to return a promise or a value. \nThe returned promise is resolved when the function finishes execution.\n\nThe `type` argument is optional and can be a `string` or an array of `strings`. \nUse it to specify the type(s) associated with the function. \n\nThe function will run as soon as a free slot is available for every `type`. \nIf no `type` is passed or is unknown, the `defaultConcurrency` is used. \n\nThe execution order is guaranteed for functions enqueued with the exact same `type` argument.\n\nExample:\n\n```js\n\nvar method = function () {\n return Q.resolve('foo');\n};\n\nvar throttler = PThrottler.create(15, {\n 'foo': 1,\n 'bar': 2\n});\n\n// Single type, will only run when a free slot for\n// \"foo\" is available\nthrottler.enqueue(function () {\n return method(); // method() returns some promise\n}, 'foo')\n.then(function (value) {\n console.log(value);\n});\n\n// Multiple type, will only run when a free slot for\n// \"foo\" and \"bar\" are available\nthrottler.enqueue(function () {\n return method(); // method() returns some promise\n}, ['foo', 'bar'])\n.then(function (value) {\n console.log(value);\n});\n```\n\n\n### .abort(): Promise\n\nAborts all current work being done.\nReturns a promise that is resolved when the current running functions finish to execute. \nAny function that was in the queue waiting to be ran is removed immediately.\n\n\n## License\n\nReleased under the [MIT License](http://www.opensource.org/licenses/mit-license.php).\n",
"readmeFilename": "README.md",
"homepage": "https://github.com/IndigoUnited/node-p-throttler#readme",
"_id": "p-throttler@0.1.1",
"_shasum": "15246409d225d3eefca85c50de710a83a78cca6a",
"_resolved": "https://registry.npmjs.org/p-throttler/-/p-throttler-0.1.1.tgz",
"_from": "p-throttler@0.1.1"
}