Is there a standard way to break while true loops with call effect when END is dispatched?
krutoo opened this issue · comments
Dmitry Petrov commented
Hi, first of all thanks for great library.
In my case i have many while true loops and i want to break them all when end is dispatched.
Unfortunately, this loops dont breaks when END is dispatched.
There is the example:
function* main () {
yield fork(infiniteUpdate);
}
function* infiniteUpdate () {
while (true) {
yield call(delay, 1000);
yield call(update);
}
}
function delay (ms) {
return new Promise(done => setTimeout(done, ms))
}
function update () {
console.log('update called');
}
when i call sagaMiddleware.run(main)
it start log every second.
after I dispatch the END it still continues to logs.
Is there a standard way to break while true loops with call effect where END is dispatched?
Dmitry Petrov commented
I was offered a good solution on discord from vijah:
while (true) {
yield race([take(END), call(someAsyncFn)]);
}
But the question remains: is this behavior a bug or a feature?