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.
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.
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 yourtakeEveryuses aforkunder 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.