ping<T> method

void ping<T>(
  1. Channel<T> channel,
  2. T? data
)

Emits new data to all listeners currently subscribed to the provided communication channel. The method validates that the channel exists before dispatching events, preventing accidental communication through invalid or forgotten channels during the application execution lifecycle.

Implementation

void ping<T>(Channel<T> channel, T? data) {
  assert(
    _channels.containsKey(channel.name),
    'Channel "${channel.name}" is not initialized.',
  );

  final listeners = _channels[channel.name]!;

  for (final listener in List<Function>.from(listeners)) {
    try {
      (listener as ChannelerCallback<T>).call(data);
    } catch (_) {
      /// Silently ignores invalid listener casting issues caused by
      /// incorrect generic registrations under the same communication
      /// channel during runtime execution inside the application.
    }
  }
}