V
V
Vann Damm2021-08-08 12:29:56
React
Vann Damm, 2021-08-08 12:29:56

How to run saga-watcher so that its saga-worker will only execute other sagas after the previous one is completed?

There is a saga-watcher, it has a saga-worker that executes other sagas
An example of a saga-worker

yield takeLatest(Actions.GET_INFO_ABOUT_USER.TRIGGER, getInfoAboutUser)

saga-worker content
function* getInfoAboutUser(
  action: ReturnType<typeof GET_INFO_ABOUT_USER.trigger>,
): Generator<StrictEffect> {
  try {
    const { userId, value } = action.payload;
    yield put(Actions.GET_USER_DATA.trigger(userId));
    yield put(Actions.SET_USER_DATA_WITH_FETCH.trigger({ userId, value }));
  } catch (e) {
    console.log(e);
  }
}

And when executing the sagas in getInfoAboutUser, the saga yield put(Actions.GET_USER_DATA.trigger(userId)); executes asynchronous actions while saga yield put(Actions.SET_USER_DATA_WITH_FETCH.trigger({ userId, value })); is executed before the completion of the first saga GET_USER_DATA.trigger, the question is how, in this context of implementation, to make the second saga be called upon completion of the first? ala putAwait

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question