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

(with minimal reproducible sample) Stream.toList stuck forever in a fake_async environment #2310

Closed
fzyzcjy opened this issue Jun 8, 2022 · 2 comments

Comments

@fzyzcjy
Copy link

fzyzcjy commented Jun 8, 2022

void main() {
  test('simple', () async {
    await fakeAsync((async) async {
      final stream = Stream.value(42);
      print('hi before await');
      await stream.toList();
      print('hi after await');
    });
  });
}

stucks forever...

I have also tried to call whatever methods, but still stuck forever in the "await" line

  test('simple', () async {
    await fakeAsync((async) async {
      final stream = Stream.value(42);
      final future = stream.toList();
      print('hi before await');
      async.flushMicrotasks();
      async.flushTimers();
      async.elapse(const Duration(seconds: 10));
      async.elapseBlocking(const Duration(seconds: 10));
      await future;
      print('hi after await');
    });
  });

I have looked at the implementation of Stream.toList as follows, but it seems quite normal

  Future<List<T>> toList() {
    List<T> result = <T>[];
    _Future<List<T>> future = new _Future<List<T>>();
    this.listen(
        (T data) {
          result.add(data);
        },
        onError: future._completeError,
        onDone: () {
          future._complete(result);
        },
        cancelOnError: true);
    return future;
  }
@fzyzcjy
Copy link
Author

fzyzcjy commented Jun 8, 2022

I see the reason... #2307

This workaround works for me: #2309

@osa1
Copy link
Member

osa1 commented Jul 13, 2022

Closing as duplicate of #2307.

@osa1 osa1 closed this as completed Jul 13, 2022
@mosuem mosuem transferred this issue from dart-archive/fake_async Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants