Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
powerpromises
Advanced tools
#powerpromises
Library for simplify the use of javascript promises library q. It allow us to chain a group of calls to a function and execute them in parallel, sequentially, or a limited parallel group of calls. Take a look at the examples:
##Parallel execution
var Q = require('q'),
pw = require('../powerpromises');
const NUMBER = 100;
var waitFn = function(number) {
var df = Q.defer();
console.log("start " + number + ".");
setTimeout(function() {
console.log("done " + number + ".");
df.resolve(true);
}, 3000);
return df.promise;
}
var arrayOfNumbers = function() {
var arr = [];
for (var i=0; i<NUMBER; i++) {
arr.push(i);
}
return arr;
};
pw.chainPromises(waitFn, arrayOfNumbers());
##Sequential execution
var Q = require('q'),
pw = require('../powerpromises');
const NUMBER = 3;
const PARALLEL = 1;
var waitFn = function(number) {
var df = Q.defer();
console.log("start " + number + ".");
setTimeout(function() {
console.log("done " + number + ".");
df.resolve(true);
}, 3000);
return df.promise;
}
var arrayOfNumbers = function() {
var arr = [];
for (var i=0; i<NUMBER; i++) {
arr.push(i);
}
return arr;
};
pw.chainPromises(waitFn, arrayOfNumbers(), PARALLEL);
##Sequential execution with limited grouped calls in parallel
var Q = require('q'),
pw = require('../powerpromises');
const NUMBER = 100;
const PARALLEL = 5;
var waitFn = function(number) {
var df = Q.defer();
console.log("start " + number + ".");
setTimeout(function() {
console.log("done " + number + ".");
df.resolve(true);
}, 3000);
return df.promise;
}
var arrayOfNumbers = function() {
var arr = [];
for (var i=0; i<NUMBER; i++) {
arr.push(i);
}
return arr;
};
pw.chainPromises(waitFn, arrayOfNumbers(), PARALLEL);
##Sequential execution with limited grouped calls in parallel and error management
var Q = require('q'),
pw = require('../powerpromises');
const NUMBER = 25;
const PARALLEL = 5;
var waitFn = function(number) {
var df = Q.defer();
console.log("start " + number + ".");
setTimeout(function() {
if ( number % 2 === 0) {
console.log("done " + number + ".");
df.resolve({ number: number, status: true });
} else {
console.log("fail " + number + ".");
df.reject({ number: number, status: false });
}
}, 3000);
return df.promise;
}
var arrayOfNumbers = function() {
var arr = [];
for (var i=0; i<NUMBER; i++) {
arr.push(i);
}
return arr;
};
pw.chainPromises(waitFn, arrayOfNumbers(), PARALLEL).then(function(results) {
console.log(results);
});
FAQs
Easy use of Q promises
The npm package powerpromises receives a total of 0 weekly downloads. As such, powerpromises popularity was classified as not popular.
We found that powerpromises 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.