Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
give-me
Advanced tools
Readme
Give-me takes care of executing deferred functions in parallel/sequence, and allows 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. The callback object is an array of callback results.
npm install give-me
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']]
});
If functions 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']]
});
When tuple argument provided it tries to return 2 arrays of results. In case the first array (supposed to be the errors) is an array of empty values it is nullified (so that callback is a function(x, y) => null, array).
var giveMe = require('give-me');
var errorFunc = function(callback){
setTimeout((function(){ callback('error'); }), 200);
};
var successFunc = function(callback){
setTimeout((function(){ callback(null, 'hello'); }), 100);
};
giveMe.all([errorFunc, successFunc], function(errors, results){
console.log(errors); // will display ['error', null]
console.log(results); // will display [null, 'hello'];
});
giveMe.all([successFunc, successFunc], function(errors, results){
console.log(errors); // will display null
console.log(results); // will display ['hello', 'hello'];
});
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]]
});
Runs an array of functions in sequence, 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.sequence([a, b], function(result){
console.log(result);
// will display [['a'],['b']] after ~300ms
});
MIT
FAQs
A simple js library to manage deferred functions with a callbacks-style syntax
The npm package give-me receives a total of 450 weekly downloads. As such, give-me popularity was classified as not popular.
We found that give-me demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.