blatann.waitables.event_queue module

class blatann.waitables.event_queue.EventQueue(event, disconnect_event=None)

Bases: Generic[TSender, TEvent]

Iterable object which provides a stream of events dispatched on a provided Event object. The iterator does not exit unless a “disconnect event” is provided, typically when a peer disconnects.

get(block=True, timeout=None)

Gets the next item in the queue. If a disconnect event occurs, the queue will return None and not return any other events afterward.

Parameters:
  • block – True to block the current thread until the next event is received

  • timeout – Optional timeout to wait for the next object

Return type:

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

Returns:

The next item in the queue

Raises:

queue.Empty if a timeout is provided and no event was received

class blatann.waitables.event_queue.AsyncEventQueue(event, disconnect_event=None, event_loop=None)

Bases: Generic[TSender, TEvent]

Asynchronous iterable object which provides a stream of events dispatched on a provided Event object. The iterator does not exit unless a “disconnect event” is provided, typically when a peer disconnects.

async get()

Asynchronously gets the next item in the queue. If a disconnect event occurs, the queue will return None and not provide any other events afterward.

Return type:

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

Returns:

The next item in the queue, or None if the disconnect event occurred