Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
conditional-race
Advanced tools
[![Build Status](https://travis-ci.org/rodrigogs/conditional-race.svg?branch=master)](https://travis-ci.org/rodrigogs/conditional-race) [![Maintainability](https://api.codeclimate.com/v1/badges/daa916d68e2291a6352a/maintainability)](https://codeclimate.co
The conditionalRace function returns a Promise
that is
settled the same way (and takes the same value) as the
first promise that settles and fulfills the passed condition function
amongst the promises of the iterable passed as argument.
If the iterable passed is empty, the promise returned will be forever pending.
If the iterable contains one or more non-promise value
and/or an already resolved/rejected promise,
then conditionalRace
will resolve to the first of these values found in the iterable.
If no promise fulfills the conditional function, null
is returned.
$ npm install conditional-race
const conditionalRace = require('conditional-race');
const run = car => new Promise(resolve => setTimeout(() => resolve(car), car.speed));
const cars = {
car1: {
number: 1,
color: 'blue',
speed: 80,
},
car2: {
number: 2,
color: 'red',
speed: 100,
},
car3: {
number: 3,
color: 'blue',
speed: 90,
},
};
// Should return the first blue car to win the race
const returnedCar = await conditionalRace([
run(cars.car1),
run(cars.car2),
run(cars.car3),
], car => car.color === 'blue');
console.log(car.number) // 3
FAQs
[![Build Status](https://travis-ci.org/rodrigogs/conditional-race.svg?branch=master)](https://travis-ci.org/rodrigogs/conditional-race) [![Maintainability](https://api.codeclimate.com/v1/badges/daa916d68e2291a6352a/maintainability)](https://codeclimate.co
We found that conditional-race 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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.