feat: improve tracker cdn (#155)

This commit is contained in:
Levi authored and GitHub committed 2023-07-15 17:01:52 +08:00
1 parent 3087796ef5
commit 80e60f4190
4 files changed
+51 -20

No files matched your search

+24
View File
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:io';
import 'package:flutter/foundation.dart';
@@ -59,4 +60,27 @@ class Util {
static isWeb() {
return kIsWeb;
}
// if one future complete, return the result, only all future error, return the last error
static anyOk<T>(Iterable<Future<T>> futures) {
final completer = Completer<T>();
Object lastError;
var count = futures.length;
for (var future in futures) {
future.then((value) {
if (!completer.isCompleted) {
completer.complete(value);
}
}).catchError((e) {
lastError = e;
count--;
print(count);
if (count == 0) {
print("completeError");
completer.completeError(lastError);
}
});
}
return completer.future;
}
}