PublishSubject<T> constructor

PublishSubject<T>({void onListen(), void onCancel(), bool sync: false })

Constructs a PublishSubject, optionally pass handlers for onListen, onCancel and a flag to handle events sync.

See also StreamController.broadcast

Implementation

factory PublishSubject(
    {void onListen(), void onCancel(), bool sync = false}) {
  // ignore: close_sinks
  final controller = StreamController<T>.broadcast(
    onListen: onListen,
    onCancel: onCancel,
    sync: sync,
  );

  return PublishSubject<T>._(
    controller,
    Observable<T>(controller.stream),
  );
}