punsubscribe method

  1. @override
Future<void> punsubscribe([
  1. List<String> patterns = const []
])
override

Unsubscribes the client from the given patterns, or all patterns if none are given.

The Future completes when the server confirms the unsubscription.

Implementation

@override
Future<void> punsubscribe([List<String> patterns = const []]) async {
  if (!_isInPubSubMode || (_subscribedPatterns.isEmpty && patterns.isEmpty)) {
    return;
  }

  // Initialize completer before executing
  if (_punsubscribeCompleter != null &&
      !_punsubscribeCompleter!.isCompleted) {
    throw ValkeyClientException(
        'Another punsubscribe operation is already in progress.');
  }
  _punsubscribeCompleter = Completer<void>();

  // execute() will now return _punsubscribeCompleter.future
  await execute(['PUNSUBSCRIBE', ...patterns]);

  // try {
  //   await execute(['PUNSUBSCRIBE', ...patterns]);
  // } catch (e) {
  //   _resetPubSubState();
  //   rethrow;
  // }

  // State updated in _handlePubSubMessage
}