{"_id":"promise-util","_rev":"13-15451a551c5104bfc4eb8310cc236c47","name":"promise-util","dist-tags":{"latest":"2.0.1"},"versions":{"0.1.1":{"name":"promise-util","version":"0.1.1","author":{"name":"Daniel Lewis"},"license":"MIT","_id":"promise-util@0.1.1","maintainers":[{"name":"mrdaniellewis","email":"npm@mrdaniellewis.co.uk"}],"homepage":"https://github.com/mrdaniellewis/node-promise-utilities","bugs":{"url":"https://github.com/mrdaniellewis/node-promise-utilities/issues"},"dist":{"shasum":"4f8b8faa41e28acdb9fa1cce1e0126a120eae4b4","tarball":"https://registry.npmjs.org/promise-util/-/promise-util-0.1.1.tgz","integrity":"sha512-3q4HVlP6JDqEwOa1ffJmQ9P6ZapWYjusrj1zBYKXhvngUTvP421oie6mBuuOnTKmeE59n0SWZlVGBmlfUsm59g==","signatures":[{"sig":"MEYCIQDZRRGEmtlzacALrJK0VpEP7ZFY41DxUoNgYK/sDhWdyQIhAKiyL3JP6IoLAyyOor07ffnonmZQ9V1PIypgIbNQ9WvA","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"_from":".","_shasum":"4f8b8faa41e28acdb9fa1cce1e0126a120eae4b4","scripts":{"test":"node test"},"_npmUser":{"name":"mrdaniellewis","email":"npm@mrdaniellewis.co.uk"},"repository":{"url":"git://github.com/mrdaniellewis/node-promise-utilities.git","type":"git"},"_npmVersion":"1.4.9","description":"Utility functions for working with Promises in Node","dependencies":{"promise-polyfill":"^1.1.2"},"devDependencies":{"test-queue":"^0.1"},"directories":{},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."},"1.0.0":{"name":"promise-util","version":"1.0.0","author":{"name":"Daniel Lewis"},"license":"ISC","_id":"promise-util@1.0.0","maintainers":[{"name":"mrdaniellewis","email":"npm@mrdaniellewis.co.uk"}],"homepage":"https://github.com/mrdaniellewis/node-promise-utilities","bugs":{"url":"https://github.com/mrdaniellewis/node-promise-utilities/issues"},"dist":{"shasum":"94c3240e2e6c486bab18aca5010bd95ff40ad48b","tarball":"https://registry.npmjs.org/promise-util/-/promise-util-1.0.0.tgz","integrity":"sha512-qAh8TMSCMufwJnWjCbJI72WHqIYTw6RpVJCFUrWAktRvixG+KThF2w5XGJJ8jT/kxgq3Koak6l5/bXHI8P7Odw==","signatures":[{"sig":"MEQCIHgt1BRGcK8BC976oiOYobHOiMsSQSLvtFbjt1JhXzs+AiAoqrUkAK8o7vTOGx9W2HHK761k2wr0DR8pa08AjcbfxA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"_from":".","_shasum":"94c3240e2e6c486bab18aca5010bd95ff40ad48b","gitHead":"4bd5fdefcdc80e825c65451859b9cb316afc7197","scripts":{"test":"mocha"},"_npmUser":{"name":"mrdaniellewis","email":"npm@mrdaniellewis.co.uk"},"repository":{"url":"git://github.com/mrdaniellewis/node-promise-utilities.git","type":"git"},"_npmVersion":"1.4.28","description":"Utility functions for working with Promises in Node","dependencies":{"promise-polyfill":"^1.1.2"},"devDependencies":{"mocha":"^2.1.0","expect":"^1.5.0","memwatch":"^0.2.2"},"directories":{},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."},"1.0.1":{"name":"promise-util","version":"1.0.1","author":{"name":"Daniel Lewis"},"license":"ISC","_id":"promise-util@1.0.1","maintainers":[{"name":"mrdaniellewis","email":"npm@mrdaniellewis.co.uk"}],"homepage":"https://github.com/mrdaniellewis/node-promise-utilities#readme","bugs":{"url":"https://github.com/mrdaniellewis/node-promise-utilities/issues"},"dist":{"shasum":"baddb02f0b0141b996d3989ac5dcb6c04cc41cd0","tarball":"https://registry.npmjs.org/promise-util/-/promise-util-1.0.1.tgz","integrity":"sha512-5JoOZ6j6nXX/UMFPeBTCyyOg79c7Z0H2ptSZ1NeW2Q5nDcwV6yQrt9pBBlRNaWwZys0Uelj4ve/FFUDUQyd5ww==","signatures":[{"sig":"MEUCIQCQ6dqBnZz7uo/xl3FvFt7WR5M+nzC5OUH8/DZ3hSVMygIgV82ybu+THCgVwA9Zqea0Zddq+oSSxSQLClUpC6KBT4Q=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"_from":".","_shasum":"baddb02f0b0141b996d3989ac5dcb6c04cc41cd0","gitHead":"b06a15cc16ec97bcc5e34b6a376e47bfd49cf6c9","scripts":{"test":"mocha"},"_npmUser":{"name":"mrdaniellewis","email":"npm@mrdaniellewis.co.uk"},"repository":{"url":"git://github.com/mrdaniellewis/node-promise-utilities.git","type":"git"},"_npmVersion":"2.11.2","description":"Utility functions for working with Promises in Node","_nodeVersion":"0.12.1","dependencies":{"promise-polyfill":"^2.0.2"},"devDependencies":{"mocha":"*","expect":"*","memwatch-next":"*"},"directories":{},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."},"1.1.0":{"name":"promise-util","version":"1.1.0","author":{"name":"Daniel Lewis"},"license":"ISC","_id":"promise-util@1.1.0","maintainers":[{"name":"mrdaniellewis","email":"npm@mrdaniellewis.co.uk"}],"homepage":"https://github.com/mrdaniellewis/node-promise-utilities","bugs":{"url":"https://github.com/mrdaniellewis/node-promise-utilities/issues"},"dist":{"shasum":"72c8340ef8ed3d37a50604dd0aa78c65d7b9bb48","tarball":"https://registry.npmjs.org/promise-util/-/promise-util-1.1.0.tgz","integrity":"sha512-GJw3cxLGRrj3QLveGkYen0E4ePoPjuTv8u2sVVYZKTdRxuJcHDpUN9dD2rXyOqndemT4uKR8Q7xazbTzaoptbg==","signatures":[{"sig":"MEQCIA0kH1gabGSfiU/D3t+B93MsnuZ+joXdpturkiT80p84AiAeaTFuUGlSJ1b0AsjEO7ysjQbjxsWLHHtlwn3nLdsBzA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"_from":".","_shasum":"72c8340ef8ed3d37a50604dd0aa78c65d7b9bb48","gitHead":"b1b6357201c1442f021cdbf9be2da83876f3372f","scripts":{"test":"mocha"},"_npmUser":{"name":"mrdaniellewis","email":"npm@mrdaniellewis.co.uk"},"repository":{"url":"git://github.com/mrdaniellewis/node-promise-utilities.git","type":"git"},"_npmVersion":"2.10.1","description":"Utility functions for working with Promises in Node","_nodeVersion":"0.12.4","dependencies":{"require-promise":"1.0.1"},"devDependencies":{"mocha":"*","expect":"*","memwatch-next":"*"},"directories":{},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."},"1.2.0":{"name":"promise-util","version":"1.2.0","author":{"name":"Daniel Lewis"},"license":"ISC","_id":"promise-util@1.2.0","maintainers":[{"name":"mrdaniellewis","email":"npm@mrdaniellewis.co.uk"}],"bugs":{"url":"https://github.com/mrdaniellewis/node-promise-utilities/issues"},"dist":{"shasum":"838a3b6c349eb94e60eb42a972d73055bc6634af","tarball":"https://registry.npmjs.org/promise-util/-/promise-util-1.2.0.tgz","integrity":"sha512-iC4n0z5I4/WtFbSngRKGSywhr8T+iSJzq32Kn0IBDUeyzUOQzcisFI7WfnfAbOHjVer/Uspg1+BH/pqtw4SW2w==","signatures":[{"sig":"MEUCIQDH/dw1aCUhMfl52gAv3VIMXbvoCzrKYYAZqD5r2VwTswIgFW3j14pjfs23jUTlcCyB3zFG8ofGxJ6kjsCVgzdEAmA=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"_from":".","_shasum":"838a3b6c349eb94e60eb42a972d73055bc6634af","gitHead":"f69ba2247677e51ecc97bd8e7ff871666aaf67be","scripts":{"test":"mocha"},"_npmUser":{"name":"mrdaniellewis","email":"npm@mrdaniellewis.co.uk"},"repository":{"url":"git://github.com/mrdaniellewis/node-promise-utilities.git","type":"git"},"_npmVersion":"2.11.2","description":"Utility functions for working with Promises in Node","_nodeVersion":"0.12.5","dependencies":{"require-promise":"1.0.1"},"devDependencies":{"mocha":"*","expect":"*","memwatch-next":"*"},"directories":{},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."},"2.0.0":{"name":"promise-util","version":"2.0.0","author":{"name":"Daniel Lewis"},"license":"ISC","_id":"promise-util@2.0.0","maintainers":[{"name":"mrdaniellewis","email":"npm@mrdaniellewis.co.uk"}],"homepage":"https://github.com/mrdaniellewis/node-promise-utilities#readme","bugs":{"url":"https://github.com/mrdaniellewis/node-promise-utilities/issues"},"dist":{"shasum":"266704e87e00e74ca01b3f37ba52515b6e3af668","tarball":"https://registry.npmjs.org/promise-util/-/promise-util-2.0.0.tgz","integrity":"sha512-IGP4A7cwMruR5VYABno3yil+Ue00vZLXYdJX2DqUHXRjt5R5Nmr2Bl+1vE0tb8T2B67x5CYvedfKzcg5nvYVyA==","signatures":[{"sig":"MEUCIQD39w6rPt9IdJIkHhGt9ttXA2Bmh07f3o01zE7t4j/PsQIgEF97O2ORDbhH9i6umgh93LogqKbGpAUZsvAb/S+JsN4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"_from":".","_shasum":"266704e87e00e74ca01b3f37ba52515b6e3af668","engines":{"node":">=4"},"gitHead":"e9b72ba0f5b37c31bd60a9b49d6570ce9fa96020","scripts":{"test":"mocha"},"_npmUser":{"name":"mrdaniellewis","email":"npm@mrdaniellewis.co.uk"},"repository":{"url":"git://github.com/mrdaniellewis/node-promise-utilities.git","type":"git"},"_npmVersion":"3.3.12","description":"Utility functions for working with Promises in Node","_nodeVersion":"5.1.0","devDependencies":{"mocha":"*","expect":"*","memwatch-next":"*"},"directories":{},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."},"2.0.1":{"name":"promise-util","version":"2.0.1","author":{"name":"Daniel Lewis"},"license":"ISC","_id":"promise-util@2.0.1","maintainers":[{"name":"mrdaniellewis","email":"npm@mrdaniellewis.co.uk"}],"homepage":"https://github.com/mrdaniellewis/node-promise-utilities#readme","bugs":{"url":"https://github.com/mrdaniellewis/node-promise-utilities/issues"},"dist":{"shasum":"f24b77ebfc30ba555f33b8f389693e4953b461dc","tarball":"https://registry.npmjs.org/promise-util/-/promise-util-2.0.1.tgz","integrity":"sha512-pcphnyYx4Jw5FEjMSNw9mnjnyBJ4PVP0SxN3HkdDcD7lLo3J24LrU1t3hrSBcrCLQ0B3b4oYWRGyCt1FQOkgIg==","signatures":[{"sig":"MEUCIQCkfAb12ImZNIoM5asVQ0ecOwzMcm+DGwkABhBFa2vg6QIgfAgjGaenT7zmNgr2h85SyXisTBwnZzUxZUsxsE/XROk=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"_from":".","_shasum":"f24b77ebfc30ba555f33b8f389693e4953b461dc","engines":{"node":">=4"},"gitHead":"53188b6b52e8807cfd8f446ae034626f9a2aecf4","scripts":{"test":"mocha"},"_npmUser":{"name":"mrdaniellewis","email":"npm@mrdaniellewis.co.uk"},"repository":{"url":"git://github.com/mrdaniellewis/node-promise-utilities.git","type":"git"},"_npmVersion":"3.3.12","description":"Utility functions for working with Promises in Node","_nodeVersion":"5.1.0","devDependencies":{"mocha":"*","expect":"*","memwatch-next":"*"},"directories":{},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."}},"time":{"created":"2014-08-18T22:07:58.461Z","modified":"2026-02-07T19:33:29.546Z","0.1.1":"2014-08-18T22:07:58.461Z","1.0.0":"2015-02-01T16:00:30.599Z","1.0.1":"2015-06-14T20:59:33.451Z","1.1.0":"2015-06-19T23:30:05.202Z","1.2.0":"2015-07-12T14:08:51.890Z","2.0.0":"2015-11-30T21:53:48.463Z","2.0.1":"2015-11-30T22:40:55.168Z"},"bugs":{"url":"https://github.com/mrdaniellewis/node-promise-utilities/issues"},"author":{"name":"Daniel Lewis"},"license":"ISC","homepage":"https://github.com/mrdaniellewis/node-promise-utilities#readme","repository":{"url":"git://github.com/mrdaniellewis/node-promise-utilities.git","type":"git"},"description":"Utility functions for working with Promises in Node","maintainers":[{"name":"mrdaniellewis","email":"npm@mrdaniellewis.co.uk"}],"readme":"# Promise utilities\n\n[![npm version](https://badge.fury.io/js/promise-util.svg)](http://badge.fury.io/js/promise-util)\n\nSome utility functions for working with Promises in node.\n\n```bash\nnpm install promise-util\n```\n\n## `wait( milliseconds, value )`\n\n`setTimeout` wrapped in a promise.\n\n* `milliseconds` Integer, time to wait\n* `value` value to return\n\n```js\nvar promiseUtil = require('promise-util');\n\npromiseUtil.wait( 1000, value )\n\t.then( function(value) {\n\t\t// Do something 1 second later\n\t} );\n```\n\n## `defer()`\n\nCreates a closure so you don't have to.  Returns a promise with `resolve()` and `reject()` methods.  \n\nUseful for converting callbacks to promises.\n\n```js\nvar promiseUtil = require('promise-util');\n\nvar defer = promiseUtil.defer();\nfs.readFile( filename, function( e, contents ) {\n\tif (e) {\n\t\tdefer.reject(e);\n\t}\n\tdefer.resolve(contents);\n} );\n```\n\n## `callback( context, fn, ...args )`\n\nCalls a function using the node callback pattern as a promise.\n\n* `context` is the context to call the function in.\n* `fn` can be the function name as a string, or the function itself.\n* `...args` arguments to pass to the function\n\nIf the callback returns more than one argument, they will be returned as an array.\n\n```js\nvar promiseUtil = require('promise-util');\n\npromiseUtil.callback( fs, 'readFile', filename )\n\t.then( /* do stuff */ );\n\n// Is equivalent to\npromiseUtil.callback( fs, fs.readFile, filename )\n\t.then( /* do stuff */ );\n\n// Is equivalent to (but in this case only because fs functions require no context)\npromiseUtil.callback( null, fs.readFile, filename )\n\t.then( /* do stuff */ ); \n```\n\nIf you want to transform a callback function into a function that generates\npromises then do this. \n\n```js\nvar readFile = promiseUtil.callback.bind( null, fs, 'readFile' );\n```\n\n## `Queue()`\n\nCreates a reusable promise.  This can be used to create a queue of tasks with an adjustable concurrency.\n\n```js\nvar Queue = require('promise-util').Queue;\n\n// Create a new queue. new is optional.\nvar queue = new Queue();\n\n// Add some tasks.\nqueue\n\t.then( function() {\n\t\t// do stuff\n\t})\n\t.then( function() {\n\t\t// do more stuff\n\t})\n\t.catch( function() {\n\t\t// catch an error\n\t})\n\t.then( \n\t\tfunction() { /* do stuff */ },\n\t\tfunction() { /* catch an error */ }\n\t);\n\n// Run the queue of tasks\nqueue.run()\n\t.then( function(value) {\n\t\t// Result of running the queue\n\t} );\n\n// Run the queue in series against a collection\nvar queue = new Queue()\n\t.then( function(value) {\n\t\treturn value*value;\n\t} )\n\t.runSeries( [1,2,3,4,5] )\n\t\t.then( function(value) {\n\t\t\t// value = [1,4,9,16,25];\n\t\t} );\n\n// See below for concurrency options\n```\n\n### Instance methods\n\n#### `Queue.prototype.then( resolveFn, rejectFn )`\n\nAdd a task to the queue.  Tasks will be run in the context of the queue.\n\n* `resolveFn` _optional_ function to resolve with\n* `rejectFn` _optional_ function to reject with\n\nReturns the `Queue` instance for chaining.\n\n#### `Queue.prototype.catch( rejectFn )`\n\nAdd a catch task to the queue\n\n* `rejectFn` function to reject with\n\nReturns the `Queue` instance for chaining.\n\n#### `Queue.prototype.run()`\n\nRun the set of tasks.\n\nReturns a `Promise`.\n\n#### `Queue.prototype.runSeries( collection, options )`\n\nRun the set of tasks against a collection in series and return the result of all tasks as a promise.\n\n* `collection` An array of values to run the queue against.\n* `options.collect` Boolean, default=true, Collect the results of each run in an array\n* `options.parallel` Integer, default=1, How many queues to run at once\n* `options.infinite` Boolean, default=false, Keep running until `finish` is called.\n\nReturns a `Promise`, with the additional methods `abort` and `finish`.\n\n* `abort()` will abort running the series.\n* `finish()` will end the series if the `infinite` option is used.\n\nThis will `shift()` the first value from the `collection` and then `run()` it.  It will continue to do this until `collection` is empty.  It then resolves the promise with an array of the results of each run.\n\n`parallel` controls how many queues are allowed to `run()` at once.\n\nIf `collect` is false than `undefined` rather than an array of results will be returned in the resolved promise.  This is useful if collection is very large.\n\nItems can be added to `collection` while it runs.  If `infinite` is true, the returned `Promise` will not resolve until `finish` is called.  If `infinite` is true, `collect` defaults to false.\n\n### Events\n\nThe `Queue` instance is an event emitter and will emit the following events:\n\n* *start* when a queue starts\n* *resolved* when a queue resolves, with the result as the first argument\n* *rejected* when a queue rejects, with the error as the fitst argument\n\n## `fifo( options )`\n\nA first in first out queue.  Runs tasks in the order they are given ensuring tasks complete before the next one starts.\n\n* `options.parallel` Integer, the number of tasks to run in parallel.  Defaults to `1`.\n\nReturns a `Function` that adds additional items to the queue.\nThe function will return a Promise resolving when the item finishes.  Items an be functions, values or promises.\n\n```js\n// Create a fifo queue\nvar fifo = require('promise-util').fifo();\n\n// Add a task\nfifo( function() {\t\n\t\treturn someLongProcessReturningAPromise();\n\t} )\n\t.then( function() {\n\t\t// Do something else\n\t} );\n```\n\n## `sequence( ar, initial )`\n\nGiven an array of functions run then as a sequence of Promises.\n\n* `ar` The array of functions\n* `initial` A starting value to pass to the first funtion\n\nReturns a Promise resolving to the value of the final function.\n\n## `spawn( generator )`\n\nGiven a generator, run the generator resolving any yielded value as a promise and return the final value.\n\nSee the \"Bonus round: Promises and Generators\" section in www.html5rocks.com/en/tutorials/es6/promises/.\n\n","readmeFilename":"README.md"}