Sdk: Future.wait track progress of resolved futures

Created on 26 Sep 2019  路  1Comment  路  Source: dart-lang/sdk

I need to track progress of resolved futures, is there a way to do it? if not, please add such feature.

area-library library-async type-enhancement

Most helpful comment

That's a fairly specialized requirement.
You have a set of futures that you are waiting on, and you want a to somehow get notified when any of the futures complete. I'm guessing for a progress bar?

I wouldn't add such functionality to the platform libraries. It might fit in package:async, say, as a specialized version of FutureGroup which reports on the status of the futures.

Until then, it's very easy to write yourself, and that also allows you to get exactly the API you need for your use-case:

Future<List<T>> progressWait<T>(List<Future<T>> futures, void progress(int completed, int total)) {
   int total = futures.length;
   int completed = 0;
   void complete() {
     completed++;
     progress(completed, total);
   }
   return Future.wait<T>([for (var future in futures) future.whenComplete(complete)]);
}

>All comments

That's a fairly specialized requirement.
You have a set of futures that you are waiting on, and you want a to somehow get notified when any of the futures complete. I'm guessing for a progress bar?

I wouldn't add such functionality to the platform libraries. It might fit in package:async, say, as a specialized version of FutureGroup which reports on the status of the futures.

Until then, it's very easy to write yourself, and that also allows you to get exactly the API you need for your use-case:

Future<List<T>> progressWait<T>(List<Future<T>> futures, void progress(int completed, int total)) {
   int total = futures.length;
   int completed = 0;
   void complete() {
     completed++;
     progress(completed, total);
   }
   return Future.wait<T>([for (var future in futures) future.whenComplete(complete)]);
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

DartBot picture DartBot  路  3Comments

55555Mohit55555 picture 55555Mohit55555  路  3Comments

ranquild picture ranquild  路  3Comments

jmesserly picture jmesserly  路  3Comments

DartBot picture DartBot  路  3Comments