consecList<R> function

FutureOr<R> consecList<R>(
  1. List<FutureOr> items,
  2. FutureOr<R> callback(
    1. List resolvedItems
    ), {
  3. void onError(
    1. Object e
    )?,
})

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;
  }
}