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

Looks like combinators dont work as intended in redux-saga #697

Open
krutoo opened this issue Feb 22, 2024 · 1 comment
Open

Looks like combinators dont work as intended in redux-saga #697

krutoo opened this issue Feb 22, 2024 · 1 comment

Comments

@krutoo
Copy link

krutoo commented Feb 22, 2024

Hi, i noticed that next code:

import { all, takeLatest } from "typed-redux-saga";

function* mySaga() {
  yield* all([
    // parallel calls
    takeLatest("HI", sayHi),
    takeLatest("BYE", sayBye),
  ]);

  console.log('after')
}

Dont works - it not prints "after" when saga run

I also noticed that this is works fine when macro version used.

I Described thoughts in readme of repo with attempt to fix that behavior:
https://github.com/krutoo/typed-redux-saga

You can also looks on tests folder in repo and check that with typed-redux-saga it is not works but with redux-saga and with fixed version it works.

Can we add a fix or something like that to typed-redux-saga?

@krutoo
Copy link
Author

krutoo commented Feb 26, 2024

After some research into the problem I found out a few details about how redux-saga works

Here's what @Vijah told me on discord:

takeLatest, takeLeading, takeEvery are not intended to be used inside all/race.

The interesting part about forks is that they are non-blocking, BUT the parent task will never finish as a result of waiting after the fork.

As a result, my guess is that takeLatest returns a fork (a task) which does not block the all, but will cause the parent generator (takeLatestWrapper) to never finish as a result of the task running indefinitely.

Also in discord @neurosnap tolds me that there are situations when it makes sense to use all() and takeLatest together:

There are cases where you want to use all() with take* helpers: for mounting a root task that spawns subtasks and never completes: https://github.com/neurosnap/redux-saga-creator/blob/master/index.ts

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