unsubscribe method

  1. @override
void unsubscribe(
  1. Subscription subscription
)
override

Removes an existing subscription.

If the subscription does not exist this method does nothing.

Implementation

@override
void unsubscribe(Subscription subscription) {
  if (subscription == null) {
    throw ArgumentError('A subscription must be provided.');
  }

  _subscriptions.remove(subscription);

  if (!_subscriptions.any((s) => s.name == subscription.name)) {
    var messenger =
        _messengers.singleWhere((m) => m.name == subscription.name);

    _messengers.remove(messenger);
    messenger.close();
  }
}