stream property

Stream<T> get stream

Returns a broadcast Stream that emits the current value and all subsequent updates to the value of this beacon.

Implementation

Stream<T> get stream {
  _controller ??= StreamController<T>.broadcast(
    onListen: () {
      // onListen is only called when sub count goes from 0 to 1.
      // If sub count goes from 1 to 0, onCancel runs and sets _unsub to null.
      // so _unsub will always be null here but checking doesn't hurt
      _unsubFromSelf ??= subscribe(
        _controller!.add,
      );
    },
    onCancel: () {
      _unsubFromSelf?.call();
      _unsubFromSelf = null;
    },
  );

  return _controller!.stream;
}