on<T> method

Stream<T> on<T>()

监听指定类型的事件

Implementation

Stream<T> on<T>() {
  if (isClosed) {
    RxLogger.warning('EventBus is closed');
    return const Stream.empty();
  }
  return _eventSubject.stream
      .where((event) => event is T)
      .cast<T>()
      .doOnData((event) {
    RxLogger.log('EventBus: Received ${T.toString()} - $event');
  }).doOnCancel(() {
    RxLogger.log(
        'EventBus: Stop listening to events of type ${T.toString()}');
  }).doOnError((error, stackTrace) {
    RxLogger.logError(error, stackTrace);
  });
}