// But let's make it async. typedef AsyncGetter = Future Function(); Future> asyncCollect(AsyncGetter getter) async { final List list = []; T value; while ((value = await getter()) != null) { list.add(value); } return list; } // Now we use it to generate and collect a bunch of scheduled tasks: Future main() async { int index = 0; final List> tasks = await asyncCollect>( () { if (index < 10) { final Completer task = Completer(); Timer(Duration(seconds: index), () { print(index); task.complete(); }); index += 1; return task.future; } return null; }, ); print(tasks.length); }