Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a standard way to break while true loops with call effect when END is dispatched? #2390

Open
krutoo opened this issue Sep 20, 2023 · 1 comment

Comments

@krutoo
Copy link

krutoo commented Sep 20, 2023

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?

@krutoo krutoo changed the title Is there a standard way to break while true loops with call effect where END is dispatched? Is there a standard way to break while true loops with call effect when END is dispatched? Sep 22, 2023
@krutoo
Copy link
Author

krutoo commented Sep 22, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant