{"_id":"ensure-async","_rev":"5903","name":"ensure-async","description":"Wrap an async function and ensure it calls its callback on a later tick of the event loop.","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"kikobeats","email":"josefrancisco.verdu@gmail.com"}],"time":{"modified":"2021-06-03T09:56:48.000Z","created":"2015-07-16T15:14:01.395Z","1.0.0":"2015-07-16T15:29:38.042Z","0.1.0":"2015-07-16T15:14:01.395Z"},"users":{},"author":{"name":"Kiko Beats","email":"josefrancisco.verdu@gmail.com","url":"https://github.com/Kikobeats"},"repository":{"type":"git","url":"git+https://github.com/kikobeats/ensure-async.git"},"versions":{"1.0.0":{"name":"ensure-async","description":"Wrap an async function and ensure it calls its callback on a later tick of the event loop.","homepage":"https://github.com/Kikobeats/ensure-async","version":"1.0.0","main":"./index.js","author":{"name":"Kiko Beats","email":"josefrancisco.verdu@gmail.com","url":"https://github.com/Kikobeats"},"repository":{"type":"git","url":"git+https://github.com/kikobeats/ensure-async.git"},"bugs":{"url":"https://github.com/Kikobeats/ensure-async/issues"},"keywords":["async","ensure","setimmediate","nexttick"],"dependencies":{"lodash.restparam":"~3.6.1","setimmediate":"~1.0.2"},"devDependencies":{"browserify":"*","coffee-script":"*","coffeeify":"*","gulp":"*","gulp-header":"*","gulp-uglify":"*","gulp-util":"*","mocha":"*","should":"*","vinyl-buffer":"*","vinyl-source-stream":"*"},"engines":{"node":">= 0.10.0","npm":">= 1.4.0"},"scripts":{"test":"sh test/test.sh"},"license":"MIT","gitHead":"5eff1a5da2dfbb17d2685107fdedff6fd26b15fe","_id":"ensure-async@1.0.0","_shasum":"f9f4c232b747d5b51d7576754e0e2754ed2bfcd6","_from":".","_npmVersion":"2.13.0","_nodeVersion":"0.10.39","_npmUser":{"name":"kikobeats","email":"josefrancisco.verdu@gmail.com"},"dist":{"shasum":"f9f4c232b747d5b51d7576754e0e2754ed2bfcd6","size":7016,"noattachment":false,"key":"/ensure-async/-/ensure-async-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/ensure-async/download/ensure-async-1.0.0.tgz"},"maintainers":[{"name":"kikobeats","email":"josefrancisco.verdu@gmail.com"}],"directories":{},"publish_time":1437060578042,"_cnpm_publish_time":1437060578042,"_hasShrinkwrap":false},"0.1.0":{"name":"ensure-async","description":"Wrap an async function and ensure it calls its callback on a later tick of the event loop.","homepage":"https://github.com/Kikobeats/ensure-async","version":"0.1.0","main":"./index.js","author":{"name":"Kiko Beats","email":"josefrancisco.verdu@gmail.com","url":"https://github.com/Kikobeats"},"repository":{"type":"git","url":"git+https://github.com/kikobeats/ensure-async.git"},"bugs":{"url":"https://github.com/Kikobeats/ensure-async/issues"},"keywords":["async","ensure","setimmediate","nexttick"],"dependencies":{"lodash.restparam":"~3.6.1","setimmediate":"~1.0.2"},"devDependencies":{"browserify":"*","coffee-script":"*","coffeeify":"*","gulp":"*","gulp-header":"*","gulp-uglify":"*","gulp-util":"*","mocha":"*","should":"*","vinyl-buffer":"*","vinyl-source-stream":"*"},"engines":{"node":">= 0.10.0","npm":">= 1.4.0"},"scripts":{"test":"sh test/test.sh"},"license":"MIT","gitHead":"382b1da062b89e44fb7aaf6cdbd551a3f56c1d41","_id":"ensure-async@0.1.0","_shasum":"8816ac3d30f14197e64563eec8a539879374f334","_from":".","_npmVersion":"2.13.0","_nodeVersion":"0.10.39","_npmUser":{"name":"kikobeats","email":"josefrancisco.verdu@gmail.com"},"dist":{"shasum":"8816ac3d30f14197e64563eec8a539879374f334","size":6560,"noattachment":false,"key":"/ensure-async/-/ensure-async-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/ensure-async/download/ensure-async-0.1.0.tgz"},"maintainers":[{"name":"kikobeats","email":"josefrancisco.verdu@gmail.com"}],"directories":{},"publish_time":1437059641395,"_cnpm_publish_time":1437059641395,"_hasShrinkwrap":false}},"readme":"# ensure-async\n\n![Last version](https://img.shields.io/github/tag/Kikobeats/ensure-async.svg?style=flat-square)\n[![Dependency status](http://img.shields.io/david/Kikobeats/ensure-async.svg?style=flat-square)](https://david-dm.org/Kikobeats/ensure-async)\n[![Dev Dependencies Status](http://img.shields.io/david/dev/Kikobeats/ensure-async.svg?style=flat-square)](https://david-dm.org/Kikobeats/ensure-async#info=devDependencies)\n[![NPM Status](http://img.shields.io/npm/dm/ensure-async.svg?style=flat-square)](https://www.npmjs.org/package/ensure-async)\n[![Gratipay](https://img.shields.io/gratipay/Kikobeats.svg?style=flat-square)](https://gratipay.com/~Kikobeats/)\n\n> Wrap an async function and ensure it calls its callback on a later tick of the event loop. Based on [async#ensureAsync](https://github.com/caolan/async#ensureAsync) as module.\n\n## Install\n\n```bash\nnpm install ensure-async --save\n```\n\nIf you want to use in the browser (powered by [Browserify](http://browserify.org/)):\n\n```bash\nbower install ensure-async --save\n```\n\nand later link in your HTML:\n\n```html\n<script src=\"bower_components/ensure-async/dist/ensure-async.js\"></script>\n```\n\n## Usage\n\n```js\nvar ensureAsync = require('ensure-async');\n\nfunction sometimesAsync(arg, callback) {\n  if (cache[arg]) {\n    return callback(null, cache[arg]); // this would be synchronous!!\n  } else {\n    doSomeIO(arg, callback); // this IO would be asynchronous\n  }\n}\n\n// this has a risk of stack overflows if many results are cached in a row\nasync.mapSeries(args, sometimesAsync, done);\n\n// this will defer sometimesAsync's callback if necessary,\n// preventing stack overflows\nasync.mapSeries(args, ensureAsync(sometimesAsync), done);\n```\n\n## API\n\n### ensureAsync(fn)\n\nWrap an async function and ensure it calls its callback on a later tick of the event loop.  If the function already calls its callback on a next tick, no extra deferral is added. This is useful for preventing stack overflows (`RangeError: Maximum call stack size exceeded`) and generally keeping [Zalgo](http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony) contained.\n\n__Arguments__\n\n* `fn` - an async function, one that expects a node-style callback as its last argument\n\nReturns a wrapped function with the exact same call signature as the function passed in.\n\n## License\n\nMIT © [Kiko Beats](http://www.kikobeats.com)\n","_attachments":{},"homepage":"https://github.com/Kikobeats/ensure-async","bugs":{"url":"https://github.com/Kikobeats/ensure-async/issues"},"license":"MIT"}