join<T> static method
Future<Iterable<CompletableIsolate<T> > >
join<T>(
- Iterable<
CompletableIsolate< completableIsolateT> >
等待所有任务完成
Implementation
static Future<Iterable<CompletableIsolate<T>>> join<T>(
Iterable<CompletableIsolate<T>> completableIsolate) async {
Completer<Iterable<CompletableIsolate<T>>> completer = Completer();
if (completableIsolate.isEmpty) {
completer.complete(Iterable.empty());
}
int count = completableIsolate.length;
Set<int> ids = {};
for (var f in completableIsolate) {
void sub() {
if (!ids.contains(f.hashCode)) {
ids.add(f.hashCode);
count--;
if (count == 0) {
completer.complete(completableIsolate);
}
}
}
f.whenComplete(sub);
f.onCancel(sub);
}
return completer.future;
}