I have a list of items to be processed. Lets says A,B,C,D,E .. I have a list of promises which processes these items. Each promise can process 1 or more items. I have a list of items which need to be mandatorily processed.
Lets say A, C are mandatory items.
- Promise 1 processes A,B
- Promise 2 processes A,C
- Promise 3 processes B,C.
I can return in any of the following cases
- P1,P2 are completed (don't care about P3)
- P1,P3 are completed (don't care about P2)
- P2,P3 are completed (don't care about P1)
- P1,P2,P3 are completed.
All promises (async calls) are started at the same item sequentially. How do I handle this with Promise of iterables.?
One way I could think of is
Promise.race(
Promise.all(P1,P2),
Promise.all(P1,P3),
Promise.all(P2,P3),
Promise.all(P1,P2,P3)
)
This should work. But this requires me to construct the list of promise combinations based on the mandatoryItems and eachPromiseItems.
Is there a proper elegant way to handle this case in JavaScript?