waitF<R> function
Waits for a list of FutureOr values and transforms the results.
Implementation
FutureOr<R> waitF<R>(
Iterable<_TFactory<dynamic>> itemFactories,
_TSyncOrAsyncMapper<Iterable<dynamic>, R> callback, {
_TOnErrorCallback? onError,
bool eagerError = true,
_TOnCompleteCallback? onComplete,
}) {
final syncBuffer = <dynamic>[];
final asyncBuffer = <Future<dynamic>>[];
_Error? syncError1;
for (final itemFactory in itemFactories) {
try {
final item = itemFactory();
if (item is Future) {
asyncBuffer.add(item);
} else {
syncBuffer.add(item);
}
} catch (e, s) {
if (eagerError) {
return _handleErrorAndComplete(_Error(e, s), onError, onComplete);
}
if (syncError1 == null) {
syncError1 = _Error(e, s);
asyncBuffer.add(Future.error(e, s));
}
}
}
if (asyncBuffer.isEmpty) {
return _handleSyncPath(
syncError1,
syncBuffer,
callback,
onError,
onComplete,
);
}
return _handleAsyncPath(
syncError1,
syncBuffer,
asyncBuffer,
eagerError,
callback,
onError,
onComplete,
);
}