consecList<R> function
Maps a synchronous or asynchronous list of values to a single value.
Implementation
FutureOr<R> consecList<R>(
List<FutureOr<dynamic>> items,
FutureOr<R> Function(List<dynamic> resolvedItems) callback, {
void Function(Object e)? onError,
}) {
try {
if (items.whereType<Future<dynamic>>().isNotEmpty) {
return Future.wait(
items.map((item) async => item),
).then((resolvedItems) {
return callback(resolvedItems);
});
} else {
return callback(items);
}
} catch (e) {
onError?.call(e);
rethrow;
}
}