blatann.waitables.event_waitable module

class blatann.waitables.event_waitable.EventWaitable(event)

Bases: Waitable, Generic[TSender, TEvent]

Waitable implementation which waits on an Event.

wait(timeout=None, exception_on_timeout=True)

Waits for the asynchronous operation to complete

Warning

If this call times out, it cannot be (successfully) called again as it will clean up all event handlers for the waitable. This is done to remove lingering references to the waitable object through event subscriptions

Parameters
  • timeout – How long to wait, or None to wait indefinitely

  • exception_on_timeout – Flag to either throw an exception on timeout, or instead return None object(s)

Return type

Tuple[TypeVar(TSender), TypeVar(TEvent)]

Returns

The result of the asynchronous operation

Raises

TimeoutError

then(callback)

Registers a function callback that will be called when the asynchronous operation completes

Note

Only a single callback is supported– subsequent calls to this method will overwrite previous callbacks

Parameters

callback (Callable[[TypeVar(TSender), TypeVar(TEvent)], None]) – The function to call when the async operation completes

Returns

This waitable object

class blatann.waitables.event_waitable.IdBasedEventWaitable(event, event_id)

Bases: EventWaitable, Generic[TSender, TEvent]

Extension of EventWaitable for high-churn events which require IDs to ensure the correct operation is waited upon, such as characteristic read, write and notify operations