addError method

  1. @override
void addError(
  1. Object errorEvent, [
  2. StackTrace? stackTrace
])
override

Adds an error to the sink.

Must not be called on a closed sink.

Implementation

@override
void addError(errorEvent, [StackTrace? stackTrace]) {
  if (!hasListener) return;
  var listeners = _subscriptions!;
  int len = listeners.length;
  for (int i = 0; i < len; i++) {
    var sub = listeners[i];
    var callback = sub._onError;
    // Cancel first in case something goes wrong in the callback.
    if (sub._cancelOnError == true) {
      sub._closeSubscription();
    }
    if (callback != null) {
      if (callback is ZoneBinaryCallback<Object, Object, Object?>) {
        callback(errorEvent, stackTrace);
      } else if (callback is ZoneUnaryCallback<Object, Object>) {
        callback(errorEvent);
      }
    }
  }
}