{"name":"run-async","version":"3.0.0","description":"Utility method to run function either synchronously or asynchronously using the common `this.async()` style.","main":"index.js","scripts":{"test":"mocha -R spec"},"engines":{"node":">=0.12.0"},"repository":{"type":"git","url":"git+https://github.com/SBoudrias/run-async.git"},"keywords":["flow","flow-control","async"],"author":{"name":"Simon Boudrias","email":"admin@simonboudrias.com"},"license":"MIT","devDependencies":{"mocha":"^10.2.0"},"gitHead":"4d2d46bb161f69ae6358089820db08b11ea60896","bugs":{"url":"https://github.com/SBoudrias/run-async/issues"},"homepage":"https://github.com/SBoudrias/run-async#readme","_id":"run-async@3.0.0","_nodeVersion":"16.17.1","_npmVersion":"8.19.2","dist":{"integrity":"sha512-540WwVDOMxA6dN6We19EcT9sc3hkXPw5mzRNGM3FkdN/vtE9NFvj5lFAPNwUDmJjXidm3v7TC1cTE7t17Ulm1Q==","shasum":"42a432f6d76c689522058984384df28be379daad","tarball":"http://registry-npm.ywwl.com/run-async/download/run-async-3.0.0.tgz","fileCount":4,"unpackedSize":7705,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCID4alwYhFsL+qioz7Ho2fgobAMuvSvgF/4V+IwZpPT3KAiEAwGQfDtzGdwDT5igM/9bKUba0nEwu8XPEOKAQl/duU7E="}],"size":3084,"noattachment":false,"key":"/run-async/-/run-async-3.0.0.tgz"},"_npmUser":{"name":"sboudrias","email":"admin@simonboudrias.com"},"directories":{},"maintainers":[{"name":"sboudrias","email":"admin@simonboudrias.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/run-async_3.0.0_1683489576261_0.5867186636383466"},"_hasShrinkwrap":false,"readme":"Run Async\n=========\n\n[![npm](https://badge.fury.io/js/run-async.svg)](http://badge.fury.io/js/run-async) [![tests](https://travis-ci.org/SBoudrias/run-async.svg?branch=master)](http://travis-ci.org/SBoudrias/run-async) [![dependencies](https://david-dm.org/SBoudrias/run-async.svg?theme=shields.io)](https://david-dm.org/SBoudrias/run-async)\n\nUtility method to run a function either synchronously or asynchronously using a series of common patterns. This is useful for library author accepting sync or async functions as parameter. `runAsync` will always run them as an async method, and normalize the multiple signature.\n\nInstallation\n=========\n\n```bash\nnpm install --save run-async\n```\n\nUsage\n=========\n\nHere's a simple example print the function results and three options a user can provide a function.\n\n```js\nvar runAsync = require('run-async');\n\nvar printAfter = function (func) {\n  var cb = function (err, returnValue) {\n    console.log(returnValue);\n  };\n  runAsync(func, cb)(/* arguments for func */);\n};\n```\n\n#### Using `this.async`\n```js\nprintAfter(function () {\n  var done = this.async();\n\n  setTimeout(function () {\n    done(null, 'done running with callback');\n  }, 10);\n});\n```\n\n#### Returning a promise\n```js\nprintAfter(function () {\n  return new Promise(function (resolve, reject) {\n    resolve('done running with promises');\n  });\n});\n```\n\n#### Synchronous function\n```js\nprintAfter(function () {\n  return 'done running sync function';\n});\n```\n\n#### Custom done factory\n```js\nvar runAsync = require('run-async');\n\nrunAsync(function() {\n  var callback = this.customAsync();\n  callback(null, a + b);\n}, 'customAsync')(1, 2)\n```\n\n#### Passing context to async method\n```js\nvar runAsync = require('run-async');\n\nrunAsync(function() {\n  assert(this.isBound);\n  var callback = this.async();\n  callback(null, a + b);\n}).call({ isBound: true }, 1, 2)\n```\n\n### runAsync.cb\n\n`runAsync.cb` supports all the function types that `runAsync` does and additionally a traditional **callback as the last argument** signature:\n\n```js\nvar runAsync = require('run-async');\n\n// IMPORTANT: The wrapped function must have a fixed number of parameters.\nrunAsync.cb(function(a, b, cb) {\n  cb(null, a + b);\n}, function(err, result) {\n  console.log(result)\n})(1, 2)\n```\n\nIf your version of node support Promises natively (node >= 0.12), `runAsync` will return a promise. Example: `runAsync(func)(arg1, arg2).then(cb)`\n\nLicence\n========\n\nCopyright (c) 2014 Simon Boudrias (twitter: @vaxilart)  \nLicensed under the MIT license.\n","publish_time":1683489576453,"_cnpm_publish_time":1683489576453,"dist-tags":{"latest":"4.0.6"}}