Skip to content

extension FutureIterable<T>.wait throws synchronously if iteration throws. #59639

Open
@stephane-archer

Description

@stephane-archer

extension FutureIterable<T>.wait does not work properly

from the documentation:

/// Similar to [Future.wait], but reports errors using a
/// [ParallelWaitError], which allows the caller to
/// handle errors and dispose successful results if necessary.

The following code:

Future<int> main() async {
  await process([1, 2, 3, 4, 5]);
  return 0;
}

Future<void> process(Iterable<int> messages) async {
  print("len: ${messages.length}");
  Iterable<Future<int>> futures = messages.map((message) {
    return fibo(message);
  });
  assert(messages.length == futures.length);
  try {
    print("before big wait");
    await futures.wait;
    print("after big wait");
  } catch (e) {
    print(e.runtimeType);
    print("$e from the end");
  }
  print("stop!");
}

Future<int> fibo(int message) {
  throw "Test error handling";
}

output:

flutter: len: 5
flutter: before big wait
flutter: String
flutter: Test error handling from the end
flutter: stop!

I don't see any sign of ParallelWaitError, as the documentation mentions. And the future returns an error at the first exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.library-asynctype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions