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

Nested asynchronous loops don't work with groupBy #726

Open
feinstein opened this issue May 30, 2023 · 1 comment
Open

Nested asynchronous loops don't work with groupBy #726

feinstein opened this issue May 30, 2023 · 1 comment
Labels
waiting for response Waiting for follow up

Comments

@feinstein
Copy link
Contributor

feinstein commented May 30, 2023

This code works just fine:

// prints:
// 0
// Instance of '_MultiStream<int>'
// 0
// 1
// Instance of '_MultiStream<int>'
// 0
// 1
// 2
// Instance of '_MultiStream<int>'
// 0
// 1
// 2
// 3
// flutter: Instance of '_MultiStream<int>'
await for (final item in Stream.fromIterable(List.generate(4, (index) => Stream.fromIterable(List.generate(index + 1, (index) => index))))) {
  await for (final item2 in item) {
    print(item2);
  }
  print(item);
}

Now if I use a groupBy it only runs once:

// prints:
// 0
await for (final item in Stream.fromIterable(List.generate(30, (index) => index)).groupBy((value) => value % 3)) {
    await for (final item2 in item) {
      print(item2);
    }
    print(item);
  }

If I remove the second await for I can see the stream emits 3 GroupedStream as expected.

@hoc081098
Copy link
Collaborator

hoc081098 commented Jun 20, 2023

The inner Stream of groupBy completes when the outer is complete. Currently, we should not use asyncExpand((s) => s or nested await for. It causes a death lock

@hoc081098 hoc081098 added the waiting for response Waiting for follow up label Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for response Waiting for follow up
Projects
None yet
Development

No branches or pull requests

2 participants