Calling successive sagas in sequence
Saga noob is here. I tried to find the correct way to do this, but I can't think of anything that solves my problem.
I have a saga that makes an API call to make a decision. Based on this solution, I can do a redirect or send another action that starts another thread in the saga.
export default function* applicationFlow(action) {
let data = { productInfo: {} };
try {
yield put(appStatusSwitch('busy', 'Processing', 'app-status.text.verifying'));
const res = yield call(api.call, data);
const decision = res.decision ? res.decision.toLowerCase() : null;
yield put(appDecision(decision));
switch (decision) {
case 'question':
yield put (appQuestions (res.questions));
// redirect to questions page
redirectTo ('/question-page');
break;
case 'pass':
case 'fail':
//dispatch an action that does another flow..yield takeLatest(APP_SUBMIT, processApplicationFlow)
yield put (submit ());
break;
default:
redirectTo('/technical-difficulty');
}
}
catch(e) {
redirectTo('/technical-difficulty');
}
finally {
yield put(appStatusSwitch('free'));
}
}
In the thread above, how to make the saga wait for completion yield put(submit())
before the thread in that generator goes to the block finally
?
source to share
If I understand your problem correctly, you can call
saga processApplicationFlow
directly instead of performing an action.
Yours case
will look like this:
case 'fail':
yield call(processApplicationFlow)
break
call
will be blocked until another saga ends.
Hope my answer was helpful.
source to share