1.0.0 • Published 5 years ago
promise-race-map v1.0.0
promise-race-map
A Promise.race
implementation that works with JavaScript map.
Background
Promise.race
is useful when you need either one of the Promise to complete before proceeding. But if you need to process the result, it isn't easy to distinguish between two promises.
Before using promise-race-map
Before using this package, you will need to write code like this.
const p1 = fn1();
const p2 = fn2();
// Given both Promise do not return falsy values
const { r1, r2 } = await Promise.race([
() => p1.then(res => ({ r1: res })),
() => p2.then(res => ({ r2: res }))
]);
if (r1) {
// Process result from fn1()
} else {
// Process result from fn2()
}
After using promise-race-map
After using this package, you can write shorter and more readable code like this.
const { r1, r2 } = await Promise.race({
r1: fn1(),
r2: fn2()
});
if (r1) {
// Process result from fn1()
} else {
// Process result from fn2()
}
Contributions
Like us? Star us.
Want to make it better? File us an issue.
Don't like something you see? Submit a pull request.
1.1.1-master.1817c1a
5 years ago
1.1.0
5 years ago
1.0.1-master.859cff9
5 years ago
1.0.1-master.176b72d
6 years ago
1.0.1-master.634140f
6 years ago
1.0.1-master.2b46c64
6 years ago
1.0.1-master.2265bff
6 years ago
1.0.1-master.d00bd97
6 years ago
1.0.0
6 years ago
0.0.0-master.7a87112
6 years ago