subscribe method

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

Adds a subscription to receive notifications when events occur.

Implementation

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

  _subscriptions.add(subscription);
  if (!_messengers.any((m) => m.name == subscription.name)) {
    _messengers.add(_Messenger(subscription.name));
  }

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

    messenger.streamController.stream
        .asBroadcastStream()
        .listen(subscription.messageHandler);
  }
}