shutdown method

Future<void> shutdown()

Shutdown the connection manager

Implementation

Future<void> shutdown() async {
  if (_isShutdown) return;

  _isShutdown = true;
  logger.info('Shutting down connection manager...');

  // Stop health monitoring
  _healthCheckTimer?.cancel();

  // Close all connections
  final closeFutures = <Future<void>>[];
  for (final connection in _connections.values) {
    closeFutures.add(connection.close());
  }

  await Future.wait(closeFutures);

  // Clear tracking
  _connections.clear();
  _reconnectAttempts.clear();
  _lastConnectAttempt.clear();

  // Close streams
  await _connectionAddedController.close();
  await _connectionRemovedController.close();
  await _messageController.close();
  await _errorController.close();

  logger.info('Connection manager shutdown complete');
}