{"name":"run-async","version":"4.0.6","description":"Utility method to run function either synchronously or asynchronously using the common `this.async()` style.","exports":{"./package.json":"./package.json",".":{"types":"./index.d.ts","default":"./index.js"}},"sideEffects":false,"scripts":{"test":"node --test test.js","lint":"npx oxlint && npx prettier --check ."},"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":{"oxlint":"^1.2.0","prettier":"^3.5.3"},"types":"./index.d.ts","gitHead":"0d81888399d3d47656dd4762e2aa1982a79c8df9","bugs":{"url":"https://github.com/SBoudrias/run-async/issues"},"homepage":"https://github.com/SBoudrias/run-async#readme","_id":"run-async@4.0.6","_nodeVersion":"24.4.1","_npmVersion":"8.19.2","dist":{"integrity":"sha512-IoDlSLTs3Yq593mb3ZoKWKXMNu3UpObxhgA/Xuid5p4bbfi2jdY1Hj0m1K+0/tEuQTxIGMhQDqGjKb7RuxGpAQ==","shasum":"d53b86acb71f42650fe23de2b3c1b6b6b34b9294","tarball":"http://registry-npm.ywwl.com/run-async/download/run-async-4.0.6.tgz","fileCount":5,"unpackedSize":7986,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCUDxE0CgsC/jMTZwYgM/+vzpWQzn/4je3VP0s6CL/NAAIgSpQkNHgtcS4KWYhXhArLwSGXfXXE1Yw4kj+BLb3CKEE="}],"size":3232,"noattachment":false,"key":"/run-async/-/run-async-4.0.6.tgz"},"_npmUser":{"name":"sboudrias","email":"admin@simonboudrias.com"},"directories":{},"maintainers":[{"name":"sboudrias","email":"admin@simonboudrias.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/run-async_4.0.6_1754662626580_0.5603995517035782"},"_hasShrinkwrap":false,"readme":"# Run Async\n\n[![npm](https://badge.fury.io/js/run-async.svg)](http://badge.fury.io/js/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\n# Installation\n\n```bash\nnpm install --save run-async\n```\n\n# Usage\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\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\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\n```js\nprintAfter(function () {\n  return \"done running sync function\";\n});\n```\n\n#### Custom done factory\n\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\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(\n  function (a, b, cb) {\n    cb(null, a + b);\n  },\n  function (err, result) {\n    console.log(result);\n  },\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\n# Licence\n\nCopyright (c) 2014 Simon Boudrias (twitter: @vaxilart)  \nLicensed under the MIT license.\n","publish_time":1754662626831,"_cnpm_publish_time":1754662626831,"dist-tags":{"latest":"4.0.6"}}