asyncutils.futures¶
Various implementations of future and task classes, eager, time-aware and supporting asynchronous and no-argument callbacks.
Classes¶
A subclass of |
|
Self-explanatory. |
|
A subclass of |
|
A subclass of |
|
A subclass of |
|
A subclass of |
|
A subclass of |
|
A subclass of |
|
Like |
|
Self-explanatory. |
Module Contents¶
- class asyncutils.futures.AsyncCallbacksFuture[T](*, loop: asyncio.AbstractEventLoop | None = ...)[source]¶
Bases:
asyncio.Future[T]A subclass of
Futurethat supports calling asynchronous callbacks and callbacks with no arguments on completion.Note
To hook into the callbacks mechanism, subclassing the C-accelerated implementation of
Futureis impossible; i.e., using many of them, for example when implementing a queue, may be slower.- add_async_callback(
- fn: collections.abc.Callable[[Self], collections.abc.Awaitable[object]],
- /,
- *,
- context: contextvars.Context | None = ...,
Add an asynchronous callback to be called when the future is done. The callback will be passed the future as an argument.
- add_noargs_async_callback(
- fn: collections.abc.Callable[[], collections.abc.Awaitable[object]],
- /,
- *,
- context: contextvars.Context | None = ...,
Add an asynchronous callback with no arguments to be called when the future is done.
- add_noargs_callback(fn: collections.abc.Callable[[], object], /, *, context: contextvars.Context | None = ...) None¶
Add a callback with no arguments to be called when the future is done.
- remove_async_callback(fn: collections.abc.Callable[[Self], collections.abc.Awaitable[object]], /) int¶
Remove an asynchronous callback. Returns the number of callbacks removed.
- remove_done_callback(fn: collections.abc.Callable[[Self], object], /) int¶
Remove a callback. Returns the number of callbacks removed.
- remove_noargs_async_callback(fn: collections.abc.Callable[[], collections.abc.Awaitable[object]], /) int¶
Remove an asynchronous callback with no arguments. Returns the number of callbacks removed.
- remove_noargs_callback(fn: collections.abc.Callable[[], object], /) int¶
Remove a callback with no arguments. Returns the number of callbacks removed.
- class asyncutils.futures.AsyncCallbacksTask[T](*, loop: asyncio.AbstractEventLoop | None = ...)[source]¶
Bases:
asyncio.Task[T],AsyncCallbacksFuture[T]Self-explanatory.
- class asyncutils.futures.TimeAwareAsyncCallbacksFuture[T](*, loop: asyncio.AbstractEventLoop | None = ...)[source]¶
Bases:
TimeAwareFuture[T],AsyncCallbacksFuture[T]A subclass of
AsyncCallbacksFuturethat can be compared to otherTimeAwareAsyncCallbacksFuture’s based on the time they were created.
- class asyncutils.futures.TimeAwareAsyncCallbacksTask[T](*, loop: asyncio.AbstractEventLoop | None = ...)[source]¶
Bases:
TimeAwareTask[T],AsyncCallbacksTask[T]A subclass of
AsyncCallbacksTaskthat can be compared to otherTimeAwareAsyncCallbacksTask’s based on the time they were created.
- class asyncutils.futures.TimeAwareFuture[T][source]¶
Bases:
asyncio.Future[T]A subclass of
Futurethat can be compared to otherTimeAwareFuture’s based on the time they were created.- __lt__(other: TimeAwareFuture[Any] | TimeAwareTask[Any], /) bool¶
- class asyncutils.futures.TimeAwareTask[T][source]¶
Bases:
asyncio.Task[T]A subclass of
Taskthat can be compared to otherTimeAwareTask’s based on the time they were created.- __lt__(other: TimeAwareFuture[Any] | TimeAwareTask[Any], /) bool¶
- class asyncutils.futures.TimeAwareUniqueCallbacksFuture[T](*, loop: asyncio.AbstractEventLoop | None = ...)[source]¶
Bases:
TimeAwareFuture[T],UniqueCallbacksFuture[T]A subclass of
UniqueCallbacksFuturethat can be compared to otherTimeAwareUniqueCallbacksFuture’s based on the time they were created.
- class asyncutils.futures.TimeAwareUniqueCallbacksTask[T](*, loop: asyncio.AbstractEventLoop | None = ...)[source]¶
Bases:
TimeAwareTask[T],UniqueCallbacksTask[T]A subclass of
UniqueCallbacksTaskthat can be compared to otherTimeAwareUniqueCallbacksTask’s based on the time they were created.
- class asyncutils.futures.UniqueCallbacksFuture[T](*, loop: asyncio.AbstractEventLoop | None = ...)[source]¶
Bases:
asyncio.Future[T]Like
AsyncCallbacksFuture, but disallow the same callback from being added twice. Removal is faster and more intuitive to use.- add_async_callback(
- fn: collections.abc.Callable[[Self], collections.abc.Awaitable[object]],
- /,
- *,
- context: contextvars.Context | None = ...,
Add an asynchronous callback to be called when the future is done. The callback will be passed the future as an argument.
- add_done_callback(fn: collections.abc.Callable[[Self], object], /, *, context: contextvars.Context | None = ...) None¶
Add a callback to be called when the future is done. The callback will be passed the future as an argument.
- add_noargs_async_callback(
- fn: collections.abc.Callable[[], collections.abc.Awaitable[object]],
- /,
- *,
- context: contextvars.Context | None = ...,
Add an asynchronous callback with no arguments to be called when the future is done.
- add_noargs_callback(fn: collections.abc.Callable[[], object], /, *, context: contextvars.Context | None = ...) None¶
Add a callback with no arguments to be called when the future is done.
- remove_async_callback(fn: collections.abc.Callable[[Self], collections.abc.Awaitable[object]], /) Literal[0, 1]¶
Remove an asynchronous callback. Returns the number of callbacks removed.
- remove_done_callback(fn: collections.abc.Callable[[Self], object], /) Literal[0, 1]¶
Remove a callback. Returns the number of callbacks removed.
- remove_noargs_async_callback(fn: collections.abc.Callable[[], collections.abc.Awaitable[object]], /) Literal[0, 1]¶
Remove an asynchronous callback with no arguments. Returns the number of callbacks removed.
- remove_noargs_callback(fn: collections.abc.Callable[[], object], /) Literal[0, 1]¶
Remove a callback with no arguments. Returns the number of callbacks removed.
- class asyncutils.futures.UniqueCallbacksTask[T](*, loop: asyncio.AbstractEventLoop | None = ...)[source]¶
Bases:
asyncio.Task[T],UniqueCallbacksFuture[T]Self-explanatory.