publish<T> method

dynamic publish<T>(
  1. String topic, {
  2. required T arguments,
})

Publish an Event to given topic.

  • topic The topic to publish to
  • arguments The arguments to pass to

Pass null in arguments if not required, And use ? with the Type the handlers.

Implementation

publish<T>(String topic, {required T arguments}) {
  List<EventHandler<T>> handlers;
  try {
    handlers = _callbackMaps[topic] ?? [];
  } catch (_) {
    throw FormatException(
        'Type mismatch between Publisher Arguments and what Subscriber Expects');
  }

  handlers.forEach((EventHandler<T> handler) {
    try {
      handler(arguments);
    } catch (_) {
      print('Error Occured while executing handler for topic $topic');
      print(_);
    }
  });
}