How to take multiple actions without knowing which one is dispatched first?
redux-saga
Solution
You can use the `all` helper. `all` creates an Effect description that instructs the middleware to run multiple Effects in parallel and wait for all of them to complete.
Your code could look like this:
function* mySaga() {
const [actionA, actionB] = yield all([
take(ACTION_A),
take(ACTION_B),
])
}
I hope my answer was helpful.
Problem
How do I wait for both ACTION_A and ACTION_B to be dispatched without knowing which one was dispatched first? I tried `const result = yield take([ACTION_A, ACTION_B])` but `result` is only the first dispatched action, whereas I need both actions. I tried `const {a, b} = yield race({a: yield take(ACTION_A), b: yield take(ACTION_B)})` but if `a` is defined, `b` is not. Remember I can't simply `yield take(ACTION_A); yield take(ACTION_B)` because I don't know which one comes first.