<commit_before>give-me
=============
[![Build Status](https://secure.travis-ci.org/matteofigus/give-me.png?branch=master)](http://travis-ci.org/matteofigus/give-me)

## How it works

Give-me takes care of executing deferred functions in parallel, and allow you to use your functions exactly as they are keeping the well-known callback style. The only convention is that the callback arguments need to be the last in every function.

## Installation

	npm install give-me

### all(functions [, arguments], callback)

Runs an array of functions in parallel, and returns (with a callback) an array of callbacks in the same order when all the functions had been called.

	var giveMe = require('give-me');

	var a = function(callback){ setTimeout((function(){ callback("a"); }), 200); };
	var b = function(callback){ setTimeout((function(){ callback("b"); }), 100); };

	giveMe.all([a, b], function(result){
		console.log(result);
		// will display [["a"],["b"]]
	});

Functions could need some parameters to work, they can be included in the optional "arguments" parameter. Just keep the callbacks in the end.

	var giveMe = require('give-me');

	var a = function(parameter1, parameter2, callback){ 
		setTimeout((function(){ 
			callback(parameter1 + " " + parameter2);
		}), 200); 
	};

	var b = function(parameter3, callback){ 
		setTimeout((function(){ 
			callback("hello", parameter3);
		}), 100); 
	};

	giveMe.all([a, b], [["hello", "world"], ["hi"]], function(result){
		console.log(result);
		// will display [["hello world"],["hello", "hi"]]
	});


### any(functions [, arguments] [, conditionalFunction], callback)
	
Runs an array of functions in parallel, but returns (with a callback) just the fastest, ignoring all the other callbacks.

	var giveMe = require('give-me');
  
    var a = function(callback){ setTimeout((function(){ callback("a"); }), 2000); };
    var b = function(callback){ setTimeout((function(){ callback("b"); }), 100); };

    giveMe.any([a, b], function(result){
    	console.log(result);
    	// will display ["[Not processed yet]",["b"]]
    });

	
Using the optional "conditionalFunction" parameter the callback will be called when the fastest callback will satisfy a requirement provided through a sync function (in the example above, the "c" function is the fastest that satisfies the condition, the callback for function b is anyway appended as processed before but it does not satisfies the requirement).

	var giveMe = require('give-me');
  
    var a = function(param, callback){ setTimeout((function(){ callback(param) }), 200); }
    var b = function(param, callback){ setTimeout((function(){ callback(param) }), 50); }
    var c = function(param, callback){ setTimeout((function(){ callback(param) }), 100); }

    giveMe.any([a, b, c], [true, false, true], function(itemCallback){
    	return itemCallback[0] == true;
    }, function(result){
    	console.log(result);
    	// will display ["[Not processed yet]", [false], [true]]
    });

## License

MIT<commit_msg>Add a Bitdeli badge to README<commit_after>give-me
=============
[![Build Status](https://secure.travis-ci.org/matteofigus/give-me.png?branch=master)](http://travis-ci.org/matteofigus/give-me)

## How it works

Give-me takes care of executing deferred functions in parallel, and allow you to use your functions exactly as they are keeping the well-known callback style. The only convention is that the callback arguments need to be the last in every function.

## Installation

	npm install give-me

### all(functions [, arguments], callback)

Runs an array of functions in parallel, and returns (with a callback) an array of callbacks in the same order when all the functions had been called.

	var giveMe = require('give-me');

	var a = function(callback){ setTimeout((function(){ callback("a"); }), 200); };
	var b = function(callback){ setTimeout((function(){ callback("b"); }), 100); };

	giveMe.all([a, b], function(result){
		console.log(result);
		// will display [["a"],["b"]]
	});

Functions could need some parameters to work, they can be included in the optional "arguments" parameter. Just keep the callbacks in the end.

	var giveMe = require('give-me');

	var a = function(parameter1, parameter2, callback){ 
		setTimeout((function(){ 
			callback(parameter1 + " " + parameter2);
		}), 200); 
	};

	var b = function(parameter3, callback){ 
		setTimeout((function(){ 
			callback("hello", parameter3);
		}), 100); 
	};

	giveMe.all([a, b], [["hello", "world"], ["hi"]], function(result){
		console.log(result);
		// will display [["hello world"],["hello", "hi"]]
	});


### any(functions [, arguments] [, conditionalFunction], callback)
	
Runs an array of functions in parallel, but returns (with a callback) just the fastest, ignoring all the other callbacks.

	var giveMe = require('give-me');
  
    var a = function(callback){ setTimeout((function(){ callback("a"); }), 2000); };
    var b = function(callback){ setTimeout((function(){ callback("b"); }), 100); };

    giveMe.any([a, b], function(result){
    	console.log(result);
    	// will display ["[Not processed yet]",["b"]]
    });

	
Using the optional "conditionalFunction" parameter the callback will be called when the fastest callback will satisfy a requirement provided through a sync function (in the example above, the "c" function is the fastest that satisfies the condition, the callback for function b is anyway appended as processed before but it does not satisfies the requirement).

	var giveMe = require('give-me');
  
    var a = function(param, callback){ setTimeout((function(){ callback(param) }), 200); }
    var b = function(param, callback){ setTimeout((function(){ callback(param) }), 50); }
    var c = function(param, callback){ setTimeout((function(){ callback(param) }), 100); }

    giveMe.any([a, b, c], [true, false, true], function(itemCallback){
    	return itemCallback[0] == true;
    }, function(result){
    	console.log(result);
    	// will display ["[Not processed yet]", [false], [true]]
    });

## License

MIT

[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/matteofigus/give-me/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

{'fraction_non_alphanumeric': 0.1554907677356657, 'fraction_numerical': 0.01182377712989958, 'mean_word_length': 4.518319928507596, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1806324', 'n_tokens_mistral': 1879, 'n_tokens_neox': 1752, 'n_words': 620}