class EventHandler(event_names: List[str], handlers: Dict[str, Callable[[Any], Any]], min_handler_names: List[str] = None)

Bases: object

Super class that registers and handle events, for objects such as Peer and Connection.

handle(event_name: str, *args) → Any

Calls a handler for a specific event if existing, passing it arguments.

Parameters:event_name (str) – the event to trigger.
Returns:whatever the handler, if existing, returns
Return type:Any
set_handler(handler_type: str, handler: Callable)

Sets a callable as an event handler.

  • handler_type (str) – the event name.
  • handler (Callable) – the handler to be called when event is triggered.
wait(event_name: str, timeout: float = None) → Any

Waits for an event to trigger and returns the handler’s return value.

  • event_name (str) – the event to wait for.
  • timeout (float, optional) – how long maximum to wait for the event, in seconds. Defaults to None.
  • ValueError – if event_name is not a valid event name for this handler.
  • HandlerMissingException – if no handler is registered for the event, while it is a necessary handler.

whatever the handler returns.

Return type: