
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
q-combinators
Advanced tools
Functions to combine q promises, capturing lots of useful, real world patterns.
Functions to combine q promises, capturing lots of useful, real world patterns used across Beamly's node.js services.
npm install q-combinators --save
All API methods below accept Q promises or any Promise/A+ implementation (e.g. bluebird or Native Promises). For backwards comptability q-combinators will use the 'Q' library internally and return Q promises by default. However if your project uses another promise implementation you can pass it to setPromiseImpl() to change this behaviour.
// use native promises
qCombinators.setPromiseImpl(global.Promise);
// use bluebird promises
qCombinators.setPromiseImpl(require('bluebird'));
Resolves an object of promises with an object of the resultant values if all promises resolve. If any promise rejects, it rejects with the same reason
// happy path
qCombinators.object.all({
x: Q('foo'),
y: Q('bar'),
z: Q('quux')
})
.then(function(object){
// object is:
// {
// x: 'foo',
// y: 'bar',
// z: 'quux'
// }
});
// sad path
qCombinators.object.all({
x: Q.reject('foo'),
y: Q(),
z: Q()
})
.then(null, function(err){
// err is 'foo'
});
Resolves an object of promises with all results, using the same format as Q.allSettled
qCombinators.object.allSettled({
x: Q.reject('foo'),
y: Q('bar'),
z: Q('quux')
})
.then(function(object){
// object is:
// {
// x: { state: 'rejected', reason: 'foo' },
// y: { state: 'fulfilled', value: 'bar' },
// z: { state: 'fulfilled', value: 'quux' }
// }
});
Resolves an object of promises with only the fulfilled values. If none of the promises fulfill, it fulfills with an empty object.
qCombinators.object.fulfilled({
x: Q.reject('foo'),
y: Q('bar'),
z: Q('quux')
})
.then(function(object){
// object is:
// {
// y: 'bar',
// z: 'quux'
// }
});
Resolves an object of promises with only the rejected values. If none of the promises are rejected, it fulfills with an empty object.
qCombinators.object.rejected({
x: Q.reject('foo'),
y: Q('bar'),
z: Q('quux')
})
.then(function(object){
// object is:
// {
// x: 'foo'
// }
});
Resolves an object of promises when the 'demanded' keys contain successful promises.
If a demanded promise fails, the returned promise will also fail.
// happy path
qCombinators.object.demand({
x: Q('foo'),
y: Q.reject('bar'),
z: Q('quux')
})
.then(function(object){
// object is:
// {
// x: 'foo',
// z: 'quux'
// }
});
// sad path
demand(['x', 'y'], {
x: Q.reject('foo'),
y: Q('bar'),
z: Q('quux')
})
.fail(function(errs){
// errs is:
// {
// x: 'foo'
// }
});
Resolves an array of promises with only the fulfilled values. If none of the promises are fulfilled, it fulfills with an empty array.
qCombinators.array.fulfilled([
Q.reject('foo'),
Q('bar'),
Q('quux')
])
.then(function(value){
// value is: ['bar', 'quux']
});
Resolves an array of promises with only the rejected values. If none of the promises are rejected, it fulfills with an empty array.
qCombinators.array.rejected([
Q.reject('foo'),
Q.reject('bar'),
Q('quux')
])
.then(function(value){
// value is: ['foo', 'bar']
});
Sequentially executes an array of promise-returning functions. The equivalent of a lot of .then
chains:
var inc = function(a){ return a + 1 };
var promise1 = function(){ return Q(1) };
qCombinators.chain([promise1, inc, inc, inc])
.then(function(val){
// val === 4
});
Composes promise-producing functions into a single promise-producing function. Composes conventionally, from right to left.
In case of failure, returns the first failing promise in order of execution.
var incP = function(a){ return Q(a + 1) };
var doubleP = function(a){ return Q(a * 2) };
var doubleThenAddTwo = qCombinators.compose(inc, inc, double);
doubleThenAddTwo(5)
.then(function(val){
// val === 12
});
Sequentially executes an array of functions which return promises, until the first promise is resolved. If all promises are rejected it itself is rejected with an array of all the failure reasons.
// happy path
qCombinators.fallback([
function() { return Q.reject('foo'); },
function() { return Q('bar'); },
function() { return Q.reject('baz'); }
])
.then(function(result){
// result is 'bar'
});
// sad path
qCombinators.fallback([
function() { return Q.reject('foo'); },
function() { return Q.reject('bar'); },
function() { return Q.reject('baz'); }
])
.fail(function(results) {
// results is:
// [
// 'foo',
// 'bar',
// 'baz'
// ]
});
Same as .fallback, but takes an array of promises, allowing fetching results in parallel, then accepting them in preferential order.
// happy path
qCombinators.fallbackParallel([
Q.reject('foo'),
Q('bar'),
Q.reject('baz')
])
.then(function(result){
// result is 'bar'
});
// sad path
qCombinators.fallbackParallel([
Q.reject('foo'),
Q.reject('bar'),
Q.reject('baz')
])
.fail(function(results) {
// results is:
// [
// 'foo',
// 'bar',
// 'baz'
// ]
});
Contributions are currently not being accepted.
This project is licensed under the BSD 3-Clause license.
FAQs
Functions to combine q promises, capturing lots of useful, real world patterns.
The npm package q-combinators receives a total of 0 weekly downloads. As such, q-combinators popularity was classified as not popular.
We found that q-combinators 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.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.