safeAddFuture method

Future<void> safeAddFuture(
  1. Future<T> future, {
  2. void onError(
    1. Object error,
    2. 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);
  }
}