close method
关闭连接
Implementation
Future<void> close() async {
if (_isClosed) return;
_isClosed = true;
_isConnected = false;
_isConnecting = false;
await _subscription?.cancel();
_subscription = null;
// 清理 SSEStream
await _sseStream?.close();
_sseStream = null;
_httpClient?.close(force: true);
_httpClient = null;
_request = null;
_response = null;
// 检查 _eventController 是否已关闭,防止重复关闭
if (!_eventController.isClosed) {
await _eventController.close();
}
}