Most applications require multiple side effects. So in this lesson, we’ll modify our TakeLatest to accept more than one saga, as well as add another saga helper called TakeEvery.
Is it correct to say: Promise.all() waits for all events to resolve before returning, but saga's all() does not (otherwise the example would have to wait for both people and planets)
the documentation says: "[all] .. creates an Effect description that instructs the middleware to run multiple Effects in parallel and wait for all of them to complete"
I don't get why mySaga is not halting/waiting until it both takeLatests are met?? Can someone elaborate on this?
function* mySaga() {
yield all([
takeLatest(TYPES.FETCH_STAR_WARS_REQUEST, fetchPerson),
takeLatest(TYPES.FETCH_STAR_WARS_PLANET_REQUEST, fetchPlanets)
]);
}
Mustafa, good question! Using the all() effect for this situation is not necessary. You can get the same effect with just a array ([]) by itself. This generator function is not invoked each time a saga is fired. It is statically passed through to the middleware like a configuration object (the sagas are essentially flatten out). It tells the middleware what to look for and which saga to invoke when a specific action creator is fired.