fail method

void fail(
  1. Object error, [
  2. StackTrace? stackTrace
])

Complete the result with an error.

The error will be available when awaiting result. If the result is never awaited, the error is silently ignored to prevent unhandled exception warnings.

Implementation

void fail(Object error, [StackTrace? stackTrace]) {
  if (!_completer.isCompleted) {
    _completer.completeError(error, stackTrace);
    // Ignore unhandled error to prevent zone error handler from firing
    // when the result is never awaited (e.g., in tests).
    _completer.future.ignore();
  }
}