when<R> method

R when<R>({
  1. required R data(
    1. T value
    ),
  2. required R done(),
  3. required R error(
    1. ErrorAndStackTrace
    ),
})

Invokes the appropriate function on the StreamNotification based on the kind.

Implementation

@pragma('vm:prefer-inline')
@pragma('dart2js:prefer-inline')
R when<R>({
  required R Function(T value) data,
  required R Function() done,
  required R Function(ErrorAndStackTrace) error,
}) {
  final self = this;
  if (self is DataNotification<T>) {
    return data(self.value);
  }

  if (self is DoneNotification) {
    return done();
  }

  if (self is ErrorNotification) {
    return error(self.errorAndStackTrace);
  }

  throw StateError('Unknown notification $self');
}