This package has been deprecated

Author message:

use run-async, it now defaults to this behavior

run-async-nodeback

1.0.2 • Public • Published

Run Async Nodeback

npm tests dependencies

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-async

Usage

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.

Readme

Keywords

Package Sidebar

Install

npm i run-async-nodeback

Weekly Downloads

0

Version

1.0.2

License

MIT

Last publish

Collaborators

  • jamestalmage