close method

Future<void> close()

Closes all connections and the pool itself.

Implementation

Future<void> close() async {
  _isClosing = true;

  // 1. Cancel waiters
  while (_waitQueue.isNotEmpty) {
    _waitQueue.removeFirst().completeError(
        ValkeyClientException('Pool is closing, request cancelled.'));
  }

  // 2. Close all clients (Idle + Leased)
  final futures = _allClients.map((c) => c.close());
  // final futures = <Future<void>>[];
  // for (final client in _allClients) {
  //   futures.add(client.close());
  // }

  await Future.wait(futures);

  _allClients.clear();
  _idleClients.clear();
  _leasedClients.clear();
}