unsubscribe method

Future<void> unsubscribe([
  1. String topic = ""
])

Unsubscribe from all subscription listeners with the specified topic.

If topic is not set, then this method will unsubscribe from all active subscriptions.

This method is no-op if there are no active subscriptions.

The related SSE connection will be autoclosed if after the unsubscribe operation there are no active subscriptions left.

Implementation

Future<void> unsubscribe([String topic = ""]) async {
  if (topic.isEmpty) {
    // remove all subscriptions
    _subscriptions.clear();
  } else {
    final subs = _getSubscriptionsByTopic(topic);

    for (final key in subs.keys) {
      _subscriptions.remove(key);
    }
  }

  return _submitSubscriptions();
}