events property
获取事件流 注意:多次调用会返回同一个流对象,不会创建多个订阅
Implementation
Stream<SSEEvent> get events {
// 如果已经创建过流,直接返回缓存的流
if (_cachedStream != null) {
return _cachedStream!;
}
_controller ??= StreamController<SSEEvent>.broadcast();
_subscription ??= _stream.listen(
_onData,
onError: _onError,
onDone: _onDone,
cancelOnError: false,
);
// 缓存流对象,避免多次调用时重复创建
_cachedStream = _controller!.stream;
return _cachedStream!;
}