'Redux saga race effect in pure javascript

In redux saga we have race effect where we can pass named promises:

const { a, b } = yield race({     // will resolve if one of them resolves
   a: call(somePromise),
   b: call(somePromise2),
});

if (a) {
  // do something because "a" resolved
}

if (b) {
  // do something because "b" resolved
}

Question: Is there a way to implement such thing in pure javascript?

const { a, b } = Promise.race({
   a: somePromise1,
   b: somePromise2,
});

but this will fail because Promise.race accepts only arrays. Is there a way to make it work as redux saga?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source