newSubscription method

void newSubscription({
  1. Function? onEvent,
  2. Function? onClose,
  3. String? channel,
  4. String? lastEventId,
})

Initialize a new subscription and replay when possible. Should not be used by the user directly.

Implementation

void newSubscription(
    {Function? onEvent,
    Function? onClose,
    String? channel,
    String? lastEventId}) {
  _logFine("New subscriber on channel $channel.");
  // create a sink for the subscription
  ProxySink<Event> sub = new ProxySink(onAdd: onEvent, onClose: onClose);
  // save the subscription
  _subsByChannel.putIfAbsent(channel, () => []).add(sub);
  // replay past events
  if (_cache != null && lastEventId != null) {
    scheduleMicrotask(() {
      _logFine("Replaying events on channel $channel from id $lastEventId.");
      _cache!.replay(sub, lastEventId, channel);
    });
  }
}