1.0.2 • Published 10 years ago
run-async-nodeback v1.0.2
Run Async Nodeback
DEPRECATED - This is now the default behavior of run-async. Just use that.
Fork of run-async that uses nodeback style callbacks (i.e. callback(err, result));
Utility method to run function either synchronously or asynchronously using the common this.async() style.
This is useful for library author accepting sync or async functions as parameter. runAsync will always run them as async method, and normalize the function handling.
runAsync.dezalgo ensures your callback is always called asynchronously.
Standard runAsync method will run your callback synchronously if user callback is synchronous. (beware of Zalgo!)
Installation
npm install --save run-asyncUsage
var runAsync = require('run-async-nodeback');
// In Async mode:
var asyncFn = function (a) {
var done = this.async();
setTimeout(function () {
done(null, 'running: ' + a);
}, 10);
};
runAsync(asyncFn, function (err, answer) {
if (err) throw err;
console.log(answer); // 'running: async'
}, 'async');
// In Sync mode:
var syncFn = function (a) {
return 'running: ' + a;
};
runAsync(syncFn, function (err, answer) {
if (err) throw err;
console.log(answer); // 'running: sync'
}, 'sync');
runAzync.dezalgo(syncFun, function (err, answer) {
if (err) throw err;
console.log(answer); // 'running: dezalgo'
}, 'dezalgo');Licence
Copyright (c) 2014 Simon Boudrias (twitter: @vaxilart)
Licensed under the MIT license.