bec_lib.callback_handler.CallbackHandler#

class CallbackHandler[source]#

Bases: object

Callback handler class

Methods

new_id

Generate a new callback id

poll

Run all pending callbacks

register

Register a callback to an event type

register_many

Register multiple callbacks to an event type

remove

Remove a registered callback by its id

run

Run all callbacks for a given event type

new_id()[source]#

Generate a new callback id

poll()[source]#

Run all pending callbacks

register(event_type: str, callback: Callable, sync=False) int[source]#

Register a callback to an event type

Parameters:
  • event_type (str) – Event type

  • callback (Callable) – Callback function

  • sync (bool, optional) – Synchronous or async callback. Defaults to False.

Returns:

Callback id

Return type:

int

register_many(event_type: str, callbacks: list[Callable], sync=False) list[int][source]#

Register multiple callbacks to an event type

Parameters:
  • event_type (str) – Event type

  • callbacks (list[Callable]) – List of callback functions

  • sync (bool, optional) – Synchronous or async callback. Defaults to False.

Returns:

List of caallback ids

Return type:

list

remove(id: int) int[source]#

Remove a registered callback by its id

Parameters:

id (int) – Callback id

Returns:

Returns the id of the removed callback. -1 if it failed.

Return type:

int

run(event_type: str, *args, **kwargs)[source]#

Run all callbacks for a given event type