newSubscription method
void
newSubscription({})
Initialize a new subscription and replay when possible. Should not be used by the user directly.
Implementation
void newSubscription({
required void Function(Event) onEvent,
required void Function() onClose,
required 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);
});
}
}