1
0
Fork 0
arangodb/js/node/node_modules/run-async
Andreas Streichardt 8a286a30d9 We are now using semistandard and eslint 2016-06-29 18:27:02 +02:00
..
.editorconfig We are now using semistandard and eslint 2016-06-29 18:27:02 +02:00
.gitattributes We are now using semistandard and eslint 2016-06-29 18:27:02 +02:00
.jshintrc We are now using semistandard and eslint 2016-06-29 18:27:02 +02:00
.npmignore We are now using semistandard and eslint 2016-06-29 18:27:02 +02:00
.travis.yml We are now using semistandard and eslint 2016-06-29 18:27:02 +02:00
LICENSE We are now using semistandard and eslint 2016-06-29 18:27:02 +02:00
README.md We are now using semistandard and eslint 2016-06-29 18:27:02 +02:00
index.js We are now using semistandard and eslint 2016-06-29 18:27:02 +02:00
package.json We are now using semistandard and eslint 2016-06-29 18:27:02 +02:00
test.js We are now using semistandard and eslint 2016-06-29 18:27:02 +02:00

README.md

Run Async

npm tests dependencies

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.

Installation

npm install --save run-async

Usage

var runAsync = require('run-async');

// In Async mode:
var asyncFn = function (a) {
  var done = this.async();

  setTimeout(function () {
    done('running: ' + a);
  }, 10);
};

runAsync(asyncFn, function (answer) {
  console.log(answer); // 'running: async'
}, 'async');

// In Sync mode:
var syncFn = function (a) {
  return 'running: ' + a;
};

runAsync(asyncFn, function (answer) {
  console.log(answer); // 'running: sync'
}, 'sync');

Licence

Copyright (c) 2014 Simon Boudrias (twitter: @vaxilart)
Licensed under the MIT license.