# `Dispatcher`

### *class* capymoa.ocl.events.Dispatcher[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/ocl/events.py#L13)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Publish events to subscribed callbacks.

Create a source, subscribe one or more handlers for an event type, and
dispatch event instances with [`notify()`](#capymoa.ocl.events.Dispatcher.notify).

```pycon
>>> 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.

#### \_\_init_\_() → [None](https://docs.python.org/3/builtins/constants.html#None)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/ocl/events.py#L28)

Initialize an empty mapping of event types to callbacks.

#### notify(event: [Event](capymoa.ocl.events.Event.md#capymoa.ocl.events.Event)) → [None](https://docs.python.org/3/builtins/constants.html#None)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/ocl/events.py#L46)

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.

#### subscribe(event_type: [type](https://docs.python.org/3/builtins/functions.html#type)[\_E] | [None](https://docs.python.org/3/builtins/constants.html#None), callable: [Callable](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)[[\_E], [None](https://docs.python.org/3/builtins/constants.html#None)]) → [None](https://docs.python.org/3/builtins/constants.html#None)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/ocl/events.py#L32)

Register a callback for a specific event class.

#### unsubscribe(event_type: [type](https://docs.python.org/3/builtins/functions.html#type)[\_E] | [None](https://docs.python.org/3/builtins/constants.html#None), callable: [Callable](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)[[\_E], [None](https://docs.python.org/3/builtins/constants.html#None)]) → [None](https://docs.python.org/3/builtins/constants.html#None)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/ocl/events.py#L39)

Remove a previously registered callback for an event class.
