Giter VIP home page Giter VIP logo

hitme's Introduction

Hitme

NPM Version

Easily handle multiple blocks of functions that should be run independent from eachother and calls a callback when everything is done.

Any errors thrown inside the functions given to the callback.

Example

var caller = hitme(function() { console.log('all done'); });

caller(function(cb) { console.log('a'); cb(null, 'a'); });
caller(function(cb) { console.log('b'); cb(null, 'b'); });

Expected result:

a
b
all done

Usage

var hitme = require('hitme');

hitme()

When calling hitme(), it will return a caller function for all your function blocks that should be run. hitme can take two arguments:

  • callback - a function to call when everything is done
  • thisArg - an optional argument to pass to the callback function as this value

The function returned by hitme(), takes only one parameter, a function. It will call this function as soon as the current block finishes execution (using setImmediate) and it should have one argument: a callback. This callback should be treated as a function with two parameters:

  • error - if something is wrong and an erorr is passed, it will call the callback passed to hitme() with the error and any given data already passed by the other functions
  • data - a value that will be passed as an additional parameter to the callback function sent to hitme().

hitme.serial()

Calling hitme.serial() has the exact same behavior and parameters of the plain hitme(), except that it won't start to execute the next function until the previous one has called its callback.

Hello World

var hitme = require('hitme');
var caller = hitme(function(err, data) { if (err) { console.log('ERROR'); console.log(err); return; } console.log(data + ' World'); });
caller(function(cb) { cb(null, 'Hello'); });

License

MIT

hitme's People

Contributors

lsmoura avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.