Allow callbacks to Stream methods to return Futures ala Future methods #12295
Labels
area-core-library
SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.
library-async
type-enhancement
A request for a change that isn't a bug
This issue was originally filed by @seaneagan
Currently we have Future.forEach which allows taking some async action on items serially. This is nice, but the completion values of the Futures are discarded, and it lacks the rich API of Streams.
For example, I have this async method:
Future<bool> checkCommandExists(String command) {
String commandChecker = Platform.isWindows ? 'where' : 'hash';
return Process.run(commandChecker, [command])
.then((ProcessResult result) => result.exitCode == 0);
}
Then I want to be able to do:
new Stream.fromIterable(['java', 'ant', 'maven'])
.where((command) => checkCommandExists.then((exists) => !exists))
.first
.then((command) => throw 'Command $command not found');
But callbacks to Stream methods such as "where" and "map" doesn't treat returning Futures specially as many of the Future methods do. At least for Streams that have a concept of order, would need to buffer the later events until the callback completes.
The text was updated successfully, but these errors were encountered: