run-async
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Run-async is a versatile utility in JavaScript programming providing the ability to execute functions either synchronously or asynchronously. It normaIn JavaScript, synchronous execution means that the functions will run sequentially from top to bottom in a predicable manner while async execution means functions can run concurrently without waiting for the previous function to complete. There's also a normalization of multiple function signatures supported. It's particularly useful when writing libraries and dealing with both sync and async functions as inputs.
To use run-async, first, you need to install it via npm with the command npm install --save run-async
. Then, require it in your JavaScript file with var runAsync = require('run-async');
. With run-async set up, there are various ways and methods to initiate the function:
this.async
method, which allows for callback function. Here's an example code:printAfter(function () {
var done = this.async();
setTimeout(function () {
done(null, 'done running with callback');
}, 10);
});
printAfter(function () {
return new Promise(function (resolve, reject) {
resolve('done running with promises');
});
});
printAfter(function () {
return 'done running sync function';
});
runAsync.cb
, which invokes the traditional callback format with a callback as the last argument.var runAsync = require('run-async');
// NOTE: The wrapped function must have a fixed number of parameters.
runAsync.cb(function(a, b, cb) {
cb(null, a + b);
}, function(err, result) {
console.log(result)
})(1, 2)
Other features of run-async like custom done factory and passing context to an async method can also be deployed as you customize it to your needs.
The documentation for run-async can be found in its readme file on its GitHub repository page. Here's the GitHub URL: https://github.com/SBoudrias/run-async. For a thorough understanding of its usage and potential, please visit and examine the details, code snippets, and guidelines provided on the readme.