safeAddFuture method
Future<void>
safeAddFuture(
- Future<
T> future, { - void onError(
- Object error,
- StackTrace stackTrace
Adds the result of a future to this controller once it completes.
If the controller is closed before the future completes, the result
is discarded. Optionally, provide onError to handle errors.
Implementation
Future<void> safeAddFuture(
Future<T> future, {
void Function(Object error, StackTrace stackTrace)? onError,
}) async {
try {
final result = await future;
safeAdd(result);
} catch (error, stackTrace) {
if (onError != null) onError(error, stackTrace);
safeAddError(error, stackTrace);
}
}