publish<T> method
Publish an Event to given topic.
topic
The topic to publish toarguments
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(_);
}
});
}