Alexey Adamovskiy Alexey Adamovskiy - 2 months ago 8x
Dart Question

Asynchronous iterable mapping in dart

Can I map some Iterable using async mapping function? Maybe it is a bug, that this code prints list of _Future imidiately, not ints after 1 or 5 seconds?

import 'dart:async';

Future<int> foo(int i) {
var c = new Completer();
new Timer(new Duration(seconds: 1), () => c.complete(i));
return c.future;

main() {
var list = [1,2,3,4,5];
var mappedList = async => await foo(i));


The expression (i) async => await foo(i) still returns a future. You can use Future.wait(mappedList) to wait till all created futures are completed.