addEvent method

int addEvent(
  1. String channel,
  2. Map<String, Object?> payload, {
  3. String? rid,
  4. Map<String, Object?>? details,
})

Rings one event and returns its id — the handle an item action is invoked with, and the only way a reporter can tie a row back to whatever it was reporting on. Zero when the core has stopped and nothing was ringed.

Implementation

int addEvent(
  String channel,
  Map<String, Object?> payload, {
  String? rid,
  Map<String, Object?>? details,
}) {
  if (_stopped) return 0;
  var safe = jsonSafeMap(payload);
  var event = RingEvent(_nextEventId++, channel, DateTime.now(), rid, safe);
  if (details != null) _stashDetails(event.id, details);
  var ring = _ring.putIfAbsent(channel, Queue.new);
  ring.add(event);
  while (ring.length > ringSize) {
    ring.removeFirst();
  }
  onEvent?.call(channel, safe);
  if (_attached.isNotEmpty) _broadcast(event.toFrame());
  return event.id;
}