Dispatcher#
- class capymoa.ocl.events.Dispatcher[source]#
Bases:
objectPublish events to subscribed callbacks.
Create a source, subscribe one or more handlers for an event type, and dispatch event instances with
notify().>>> source = Dispatcher() >>> def handler(event: Event): print(f"Received event: {type(event).__name__}") >>> source.subscribe(Event, handler) >>> source.notify(Event()) Received event: Event
Subscriptions are keyed by exact event class.
- notify(event: Event) None[source]#
Notify all subscribers of an event.
Only subscribers of the exact event type will be notified. Subscribers of parent event types will not be notified.