{"_id":"@atomiq/promisify","_rev":"10-6080e2dc4ea6ed8b2d04b0e92f3d9a42","name":"@atomiq/promisify","description":"Convert callback-based functions to use io.js promises","dist-tags":{"latest":"0.0.4"},"versions":{"0.0.1":{"name":"@atomiq/promisify","version":"0.0.1","description":"Convert callback-based functions to use io.js promises","engines":{"node":"^2.0.0"},"main":"index.js","scripts":{"test":"mocha -- --harmony_arrow_functions","debug":"DEBUG=*,-mocha:* mocha -- --harmony_arrow_functions"},"repository":{"type":"git","url":"git+https://github.com/atomiqio/promisify-iojs.git"},"keywords":["promise","promisify","callback","iojs","es6","ecmascript"],"author":{"name":"Tony Pujals","email":"tony@subfuzion.com","url":"http://twitter.com/subfuzion"},"license":"ISC","bugs":{"url":"https://github.com/atomiqio/promisify-iojs/issues"},"homepage":"https://github.com/atomiqio/promisify-iojs#readme","dependencies":{"debug":"^2.2.0","denodeify":"^1.2.1"},"devDependencies":{"lodash":"^3.9.3","mocha":"^2.2.5"},"gitHead":"7033fa6063f879fd2ff1d0482c056ddabaa54cc5","_id":"@atomiq/promisify@0.0.1","_shasum":"1668f1c6fa2c6fb8c61065429a04933a24e9c506","_from":".","_npmVersion":"2.10.1","_nodeVersion":"2.1.0","_npmUser":{"name":"atomiq","email":"tony@atomiq.io"},"dist":{"shasum":"1668f1c6fa2c6fb8c61065429a04933a24e9c506","tarball":"https://registry.npmjs.org/@atomiq/promisify/-/promisify-0.0.1.tgz","integrity":"sha512-mPHRVa7PSNZ8lnNY/eUcNjIXl+eG+XrItUvAsNFQ1u3y4KIrb6B24q5yhrVZ5+yJJBeK1lSMLmPMc8EF7KubNA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDhIpXS+s3D1yXr9pdrEET5APVhy7jb/eLqTkWCryjMVgIhAKTrfaDaTADuNLSB3Kq7eknC7DaoUaGkmwKaJ5hXf5lq"}]},"maintainers":[{"name":"atomiq","email":"tony@atomiq.io"}],"deprecated":"WARNING: This project has been renamed to promisify-lite. Install using promisify-lite instead."},"0.0.2":{"name":"@atomiq/promisify","version":"0.0.2","description":"Convert callback-based functions to use io.js promises","engines":{"node":"^2.0.0"},"main":"index.js","scripts":{"test":"mocha -- --harmony_arrow_functions","debug":"DEBUG=*,-mocha:* mocha -- --harmony_arrow_functions"},"repository":{"type":"git","url":"git+https://github.com/atomiqio/promisify-iojs.git"},"keywords":["promise","promisify","callback","iojs","es6","ecmascript"],"author":{"name":"Tony Pujals","email":"tony@subfuzion.com","url":"http://twitter.com/subfuzion"},"license":"ISC","bugs":{"url":"https://github.com/atomiqio/promisify-iojs/issues"},"homepage":"https://github.com/atomiqio/promisify-iojs#readme","dependencies":{"debug":"^2.2.0","denodeify":"^1.2.1"},"devDependencies":{"lodash":"^3.9.3","mocha":"^2.2.5"},"gitHead":"2ce862b122123930ecf98f1d0b0fd150e904cb34","_id":"@atomiq/promisify@0.0.2","_shasum":"6d79d721529a198d41d5078d0da3289c03e4ddf4","_from":".","_npmVersion":"2.10.1","_nodeVersion":"2.1.0","_npmUser":{"name":"atomiq","email":"tony@atomiq.io"},"dist":{"shasum":"6d79d721529a198d41d5078d0da3289c03e4ddf4","tarball":"https://registry.npmjs.org/@atomiq/promisify/-/promisify-0.0.2.tgz","integrity":"sha512-GaowYNHLn/kigazg76lG2HLTkCr6INamXENfTPZoCPvOCODDJs4L/ccQJU1fAWnsCJf2Qm3AfOvWXS9EfSaDKQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDb8+5YSg20aZDLi/Gm4h9MOCiej4vj1AFDoOG7Q+jDoAIhAOT/JK4M2ZQ4kydXU9qdtjghjtkKdwr6nYSZ6TAjjvE/"}]},"maintainers":[{"name":"atomiq","email":"tony@atomiq.io"}],"deprecated":"WARNING: This project has been renamed to promisify-lite. Install using promisify-lite instead."},"0.0.3":{"name":"@atomiq/promisify","version":"0.0.3","description":"Convert callback-based functions to use io.js promises","engines":{"node":"^2.0.0"},"main":"index.js","scripts":{"test":"mocha -- --harmony_arrow_functions","debug":"DEBUG=*,-mocha:* mocha -- --harmony_arrow_functions"},"repository":{"type":"git","url":"git+https://github.com/atomiqio/promisify-iojs.git"},"keywords":["promise","promisify","callback","iojs","es6","ecmascript"],"author":{"name":"Tony Pujals","email":"tony@subfuzion.com","url":"http://twitter.com/subfuzion"},"license":"ISC","bugs":{"url":"https://github.com/atomiqio/promisify-iojs/issues"},"homepage":"https://github.com/atomiqio/promisify-iojs#readme","dependencies":{"debug":"^2.2.0","denodeify":"^1.2.1"},"devDependencies":{"lodash":"^3.9.3","mocha":"^2.2.5"},"gitHead":"f33afa5a15f866d6e1c5f3eea8ec4ea33f7cf4d0","_id":"@atomiq/promisify@0.0.3","_shasum":"94c70f0cb1911dcf7b652742d0a86aebd892f651","_from":".","_npmVersion":"2.10.1","_nodeVersion":"2.1.0","_npmUser":{"name":"atomiq","email":"tony@atomiq.io"},"dist":{"shasum":"94c70f0cb1911dcf7b652742d0a86aebd892f651","tarball":"https://registry.npmjs.org/@atomiq/promisify/-/promisify-0.0.3.tgz","integrity":"sha512-HH5A4Nke4wfF25aDfogUaVnR67NEG6YPg+48VjQwzo1BI9s3+hgxobAXAo1nl3aHibk8dhlTeTg2TPi9davN5g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDUCalRzwVsx0neas7+caS5epg+bszc67E3UjVmL0Er2AIhAI1gRr09OGDVxzwlxTpHw+vopl7nSyM+K1hcO7bl7dRi"}]},"maintainers":[{"name":"atomiq","email":"tony@atomiq.io"}],"deprecated":"WARNING: This project has been renamed to promisify-lite. Install using promisify-lite instead."},"0.0.4":{"name":"@atomiq/promisify","version":"0.0.4","description":"Convert callback-based functions to use io.js promises","engines":{"node":"^2.0.0"},"main":"index.js","scripts":{"test":"mocha -- --harmony_arrow_functions","debug":"DEBUG=*,-mocha:* mocha -- --harmony_arrow_functions"},"repository":{"type":"git","url":"git+https://github.com/atomiqio/promisify-iojs.git"},"keywords":["promise","promisify","callback","iojs","es6","ecmascript"],"author":{"name":"Tony Pujals","email":"tony@subfuzion.com","url":"http://twitter.com/subfuzion"},"license":"ISC","bugs":{"url":"https://github.com/atomiqio/promisify-iojs/issues"},"homepage":"https://github.com/atomiqio/promisify-iojs#readme","dependencies":{"debug":"^2.2.0","denodeify":"^1.2.1"},"devDependencies":{"lodash":"^3.9.3","mocha":"^2.2.5"},"gitHead":"22aed877e38f93c9c8b23541c86e3c7e3f6f7e87","_id":"@atomiq/promisify@0.0.4","_shasum":"a072e1e5efb4b421920f1b291fff2f2ee48c23b9","_from":".","_npmVersion":"2.10.1","_nodeVersion":"2.1.0","_npmUser":{"name":"atomiq","email":"tony@atomiq.io"},"dist":{"shasum":"a072e1e5efb4b421920f1b291fff2f2ee48c23b9","tarball":"https://registry.npmjs.org/@atomiq/promisify/-/promisify-0.0.4.tgz","integrity":"sha512-0tsCIGcUOtBNQ0WFv1WBrQVkdBeTGoCioDkD06EYTWkTuibkHwkaDmk9sgSrsxrowsg/9Pox48d/eli/jTN3xQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDGwW1sd4FJyg+4cst5gNzO/atDBeNg/i0hjtbYzLn44wIgUJAlN/eXmUT5sx+a5mm17/nnEAYa0PQI76p9ysvoA30="}]},"maintainers":[{"name":"atomiq","email":"tony@atomiq.io"}],"deprecated":"WARNING: This project has been renamed to promisify-lite. Install using promisify-lite instead."}},"readme":"@atomiq/promisify\n=================\n\n[npm package](https://www.npmjs.com/package/@atomiq/promisify)\n\n    npm install @atomiq/promisify\n\n\nConvert idiomatic async functions that expect callbacks to EcmaScript 2015 promises.\n\n`promisify` is a very lightweight implementation that wraps callback-style async\nfunctions with native io.js promises.\n\nPromisify an object or function and it will walk over all member properites\nand up prototype chains to ensure all callback-style async functions are converted\nto promises. The easiest thing is to just promisify modules when loading them. \n\n`promisify` looks for functions that have one of the following names as the last\nparameter: `callback`, `cb`, `done`, `callback_`, `cb_`. It recognizes both standard\nfunctional declarations as well as ES6 fat arrow functions.\n\nUnder the hood, `promisify` uses [denodeify](https://www.npmjs.com/package/denodeify)\nto create the promise wrapper over individual async functions. \n\nThis package uses the new scoped package support available with `npm` versions greater than 2.7.0.\nIf you're not familiar with using scoped packages, see [this page](https://docs.npmjs.com/getting-started/scoped-packages).\n\n## Example: promisify a loaded module\n\n```js\n    const promisify = require('@atomiq/promisify');\n\n    const fs = promisify(require('fs'));\n    \n    let f = require('path').join(__dirname, './file.txt');\n    \n    fs.readFile(f, 'utf8')\n        .then(data => {\n          // do something with data\n        })\n        .catch(err => {\n          // handle error\n        });\n\n  });\n\n```\n\nBy promisifying `fs`, you can use the above style instead of the typical\ncallback style shown below:\n\n```js\n    var fs = require('fs');\n    \n    var f = require('path').join(__dirname, './file.txt');\n    \n    fs.readFile(f, 'utf8', function(err, data) {\n      if (err) {\n        // handle error\n      } else {\n        do something with data\n      }\n    }\n```\n\n## Example: promisify a specific function\n\n```js\n\n    var asyncFunc = function(callback) {\n      // call back with result asynchronously\n      setImmediate(() => callback(null, true));\n    }\n\n    // or, with with io.js fat arrow support (`node --harmony_arrow_functions`)\n    let asyncFunc = callback => {\n      // call back with result asynchronously\n      setImmediate(() => callback(null, true));\n    };\n\n    let p = promisify(asyncFunc);\n\n    p().then(result => {\n      // do something with result\n    }).catch(err => {\n      // handle error\n    });\n```\n\n### More examples\n\nSee tests for more examples.\n\n    npm test\n\n\n## A bit more information\n\nFor trivial examples, promises might not seem to offer much of a difference over\nstandard callback-style async functions. However, one of the nice features of promises\nis that promise handlers can be chained, avoiding the \"Pyramid of Doom\" of nested\ncallbacks in more complicated control flow situations. This makes control flow logic\neasier to write and easier to follow. Compare the following example:\n\nIdiomatic Node async callbacks\n\n```js\n    asyncFunc(function(err, data) {\n      if (err) { /* handle error */ }\n      anotherAsyncFunc(function(err, data) {\n        if (err) { /* handle error */ }\n        andAnotherAsyncFunc(function(err, data) {\n          if (err) { /* handle error */ }\n          // finish processing data\n        });\n      });\n    });\n```\n\nPromise version\n\n```\n    asyncFunc(function(data) {\n      // process data\n      return anotherAsyncFunc();\n    })\n    .then(function(data) {\n      // process data\n      return andAnotherAsyncfunc();\n    })\n    .then(function(data) {\n      // finish processing data\n    })\n    .catch(function(err) {\n      // handle error\n    });\n```\n\n","maintainers":[{"name":"subfuzion","email":"tony@subfuzion.com"}],"time":{"modified":"2022-06-12T14:51:13.669Z","created":"2015-05-28T03:47:12.156Z","0.0.1":"2015-05-28T03:47:12.156Z","0.0.2":"2015-05-28T04:01:40.955Z","0.0.3":"2015-05-28T04:13:16.598Z","0.0.4":"2015-05-31T16:23:18.523Z"},"homepage":"https://github.com/atomiqio/promisify-iojs#readme","keywords":["promise","promisify","callback","iojs","es6","ecmascript"],"repository":{"type":"git","url":"git+https://github.com/atomiqio/promisify-iojs.git"},"author":{"name":"Tony Pujals","email":"tony@subfuzion.com","url":"http://twitter.com/subfuzion"},"bugs":{"url":"https://github.com/atomiqio/promisify-iojs/issues"},"license":"ISC","readmeFilename":"README.md"}