Redux-saga: Call doesn't return if yields takeEvery inside.

Created on 24 Mar 2017  路  3Comments  路  Source: redux-saga/redux-saga

Hello,

I am using the latest version on redux-saga.

I've noticed a behaviour which in my opinion is different than documentation describes it.

Doing

function* foo() {
  yield takeEvery('TEST', foo_a);
}

function* bar() {
  yield call(foo);
  console.log('hello');
}

the 'hello' is never printed. Since takeEvery is non-blocking, why the call doesn't return _immediately_?

Repository with demo: https://github.com/pilaas/redux-saga-problem
Installing and running just like in create-react-app app.

docs good first issue help wanted

Most helpful comment

The behaviour is documented in the docs, but rather poorly - you can read about fork model here. It states that "A Saga terminates only after: It terminates its own body of instructions, All attached forks are themselves terminated".

Called generator (foo) is also a saga and your takeEvery uses a fork under the hood. However the behaviour is implicit.

The docs need to be revamped a little bit about this issue, should be explained better. Hoping somebody can chime in and improve it.

All 3 comments

The behaviour is documented in the docs, but rather poorly - you can read about fork model here. It states that "A Saga terminates only after: It terminates its own body of instructions, All attached forks are themselves terminated".

Called generator (foo) is also a saga and your takeEvery uses a fork under the hood. However the behaviour is implicit.

The docs need to be revamped a little bit about this issue, should be explained better. Hoping somebody can chime in and improve it.

dang this issue really caused me a lot of headache :/

+1 for making that more obvious in the docs

This was surprising.

My intuition is that these two code snippets are equivalent:

// 1
function start() {
  window.addEventListener('resize', resizeHandler);
  console.log('done');
}
// 2
function installHandlers() {
  window.addEventListener('resize', resizeHandler);
}

function start() {
  installHandlers();
  console.log('done');
}

So it was unexpected to learn that yield call, which seemed to be the Saga equivalent of such a function call, changes the execution order.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sompylasar picture sompylasar  路  3Comments

fdesrosiers picture fdesrosiers  路  3Comments

Zacqary picture Zacqary  路  3Comments

neurosnap picture neurosnap  路  3Comments

davidwparker picture davidwparker  路  3Comments