I have three promises, Rest requests returning lists of data.
The third one has references (ids) to the first two lists, so I want to map these ids to corresponding names when I have all the data.
The mapping isn't an issue, I just use Lodash for that.
But the issue is to wait for the three promises to resolve before starting to computing this mapping.
I figured out to use concat()
:
Rx.Observable.concat(p1, p2, p3).subscribe(
function onNext(list)
{
// Assign the list to the corresponding variable in the scope
},
function onError(e)
{
// Notify of error
},
function onCompleted()
{
// Do the mapping
}
);
My problem is that onNext()
will be called in random order. Ie. I don't know which list I receive at some point, and it is hard to tell from the data it contains.
Is there a way to track which promises produced which list? A kind of zip? concatMap? concatMapObserver? I admit I haven't fully understood the usage of the last two...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…