Zanko
Zanko

Reputation: 4694

Redux-saga fork with takevery benefits

Any benefits using redux-saga in such a way?

export function* saga1() {
  yield takeEvery("DO SOMETHING", function*() {

    ...
  });
}
export default function* rootSaga() {
  yield all([
    fork(saga1),
  ]);
}

vs

export function* saga1() {
  yield takeEvery("DO SOMETHING", function*() {

    ...
  });
}
export default function* rootSaga() {
  yield all([
    saga1,
  ]);
}

The difference is the rootSaga having "fork". I know that takeEvery is essentially `take + fork. Yet I still see people do it in such way. Any real benefits or totally redundant and should be avoided?

Upvotes: 1

Views: 299

Answers (1)

Alex
Alex

Reputation: 2748

The only difference I can think of is that rootSaga will be "done" in the fork case.

In the non fork case, all will wait until saga1 is finished which will never happen, so also rootSaga will never be "done".

Practically this will not make a difference in most cases.

Upvotes: 1

Related Questions