iot_firmware.event.handler

Module in charge of handling function event subscriptions.

Classes

EventHandler([num_workers, buffer_maxsize, ...])

Class that handles Events.

PoisonPill()

Poison pill used to stop the workers gracefully.

class iot_firmware.event.handler.EventHandler(num_workers: int = 10, buffer_maxsize: int = 100, worker_timeout_seconds: float = 2, state: EventHandlerState = EventHandlerState.IDLE)[source]

Class that handles Events.

It is in charge to execute all subscribed functions to an Event.

Basic usage.

>>> event_handler = EventHandler()
>>> event_handler.state.name
'IDLE'
num_workers: int = 10
buffer_maxsize: int = 100
worker_timeout_seconds: float = 2
state: EventHandlerState = 1
subscribe(event_class: Type[Event], fn: Callable) None[source]

Subscribes a function to an EventType.

Parameters
  • event_class – event class that contains an event type

  • fn – function that is going to be called with the event object

unsubscribe(event_class: Type[Event], fn: Callable) None[source]

Unsubscribes a function to an EventType.

Parameters
  • event_class – event class that contains an event type

  • fn – function that is going to be called with the event object

publish(event: Event) None[source]

Adds the event into a queue buffer to be processed.

Parameters

event – standard event inherited from Event class

async run()[source]

Main function that starts workers to handle event requests.

async stop() None[source]

Send poison pills to all workers.

cancel() None[source]

Cancels all workers.

class iot_firmware.event.handler.PoisonPill[source]

Poison pill used to stop the workers gracefully.