asyncutils.events¶
Event with the interface it specifies, without inheriting from it.asyncio.events submodule, which manages the event loop, despite the common name.Classes¶
An event class that can store a value and maintains a history of past values. |
|
Essentially wraps a future in the event interface. |
Module Contents¶
- class asyncutils.events.EventWithValue[T: ty_extensions.Not[None]](*, maxhist: int | None = ...)[source]¶
Bases:
asyncutils.mixins.EventMixin[T]An event class that can store a value and maintains a history of past values.
A maximum of
maxhistentries, which defaults tocontext.EVENT_WITH_VALUE_DEFAULT_MAX_HIST, of past results, are stored.- get(default: T = ...) T[source]¶
Get the result of the event immediately if set, otherwise returning
defaultif passed or throwRuntimeError.
- recent_history(duration: float | None = ...) collections.abc.Generator[tuple[float, T]][source]¶
Yield recent history entries in order; what qualifies as recent depends on
duration, defaulting tocontext.EVENT_WITH_VALUE_DEFAULT_RECENT.
- remove_done_waiters() None[source]¶
Should be run periodically to cleanup the internal queue of waiters, removing those having already completed.
- set(value: None, *, strict: Literal[False]) None[source]¶
- set(value: T, *, strict: bool = ...) None
Set the result of the event and wake up waiters. If
strictisTrue, throws an error when the value isNone, since it is more idiomatic to callclear()instead.
- set_once(value: T) None[source]¶
Set the result to
value, and then immediately revert it to the original. Waiters are triggered twice.
- async wait_for_next(timeout: float | None = ...) T[source]¶
Wait for the next result of the event to be set.
- async wait_for_transition(old: T, new: T, timeout: float | None = ..., *, force_transition: bool = ..., legacy: bool = ...) bool[source]¶
- Wait until the value is set to
old, and thennew, in that order.timeoutdefaults tocontext.EVENT_WITH_VALUE_DEFAULT_TIMEOUTOn timeout, ifforce_transitionisTrue, cause the transition to happen manually.Return whether the transition occurred naturally.Changed in version 0.9.6: Fixed a bug where overlapping potential transitions are not considered. The old behaviour can be achieved by passing
legacy=True.
- async wait_for_transition_unordered( ) bool[source]¶
Wait until either
atransitions toborbtransitions toa, with the preference being for the former.
- class asyncutils.events.SingleWaiterEventWithValue[T][source]¶
Bases:
asyncutils.mixins.EventMixin[T]Essentially wraps a future in the event interface.
- get(default: T = ...) T[source]¶
Get the result of the event immediately if set, otherwise returning
defaultif passed or throwRuntimeError.