listen<T> method

  1. @override
StreamSubscription<T> listen<T>(
  1. Stream<T> stream,
  2. void listener(
    1. T it
    ), {
  3. void onDone()?,
  4. void onError(
    1. Object error,
    2. StackTrace
    )?,
})
override

Implementation

@override
StreamSubscription<T> listen<T>(
  Stream<T> stream,
  void Function(T it) listener, {
  void Function()? onDone,
  void Function(Object error, StackTrace)? onError,
}) {
  final controller = StreamController<T>(sync: true);
  onInit(() {
    final subscription = stream.listen(controller.add, onDone: controller.close, onError: controller.addError);
    onDispose(() {
      subscription.cancel();
      controller.close();
    });
  });
  return controller.stream.listen(listener, onDone: onDone, onError: onError);
}