asyncutils.futures

Various implementations of future and task classes, eager, time-aware and supporting asynchronous and no-argument callbacks.

Classes

AsyncCallbacksFuture

A subclass of Future that supports calling asynchronous callbacks and callbacks with no arguments on completion.

AsyncCallbacksTask

The above, but a task.

EagerAsyncCallbacksFuture

A subclass of AsyncCallbacksFuture that uses an eager task factory.

EagerAsyncCallbacksTask

A subclass of AsyncCallbacksTask that uses an eager task factory.

EagerTimeAwareAsyncCallbacksFuture

A subclass of TimeAwareAsyncCallbacksFuture that uses an eager task factory.

EagerTimeAwareAsyncCallbacksTask

A subclass of TimeAwareAsyncCallbacksTask that uses an eager task factory.

TimeAwareAsyncCallbacksFuture

A subclass of AsyncCallbacksFuture that can be compared to other TimeAwareAsyncCallbacksFuture's based on the time they were created.

TimeAwareAsyncCallbacksTask

A subclass of AsyncCallbacksTask that can be compared to other TimeAwareAsyncCallbacksTask's based on the time they were created.

TimeAwareFuture

A subclass of Future that can be compared to other TimeAwareFuture's based on the time they were created.

TimeAwareTask

A subclass of Task that can be compared to other TimeAwareTask's based on the time they were created.

Module Contents

class asyncutils.futures.AsyncCallbacksFuture[T](*, loop: asyncio.AbstractEventLoop | None = ...)[source]

Bases: asyncio.Future[T]

A subclass of Future that supports calling asynchronous callbacks and callbacks with no arguments on completion.

Note

To hook into the callbacks mechanism, subclassing the C-accelerated implementation of Future in _asyncio is 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.Coroutine[Any, Any, Any]],
/,
*,
context: contextvars.Context | None = ...,
) None[source]

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.Coroutine[Any, Any, Any]],
/,
*,
context: contextvars.Context | None = ...,
) None[source]

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[source]

Add a callback with no arguments to be called when the future is done.

remove_async_callback(fn: collections.abc.Callable[[Self], collections.abc.Coroutine[Any, Any, Any]], /) int

Remove an asynchronous callback. Returns the number of callbacks removed.

remove_noargs_async_callback(fn: collections.abc.Callable[[], collections.abc.Coroutine[Any, Any, Any]], /) 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]

The above, but a task.

class asyncutils.futures.EagerAsyncCallbacksFuture[T](*, loop: asyncio.AbstractEventLoop | None = ...)[source]

Bases: AsyncCallbacksFuture[T]

A subclass of AsyncCallbacksFuture that uses an eager task factory.

class asyncutils.futures.EagerAsyncCallbacksTask[T](*, loop: asyncio.AbstractEventLoop | None = ...)[source]

Bases: AsyncCallbacksTask[T], EagerAsyncCallbacksFuture[T]

A subclass of AsyncCallbacksTask that uses an eager task factory.

class asyncutils.futures.EagerTimeAwareAsyncCallbacksFuture[T](*, loop: asyncio.AbstractEventLoop | None = ...)[source]

Bases: TimeAwareAsyncCallbacksFuture[T], EagerAsyncCallbacksFuture[T]

A subclass of TimeAwareAsyncCallbacksFuture that uses an eager task factory.

class asyncutils.futures.EagerTimeAwareAsyncCallbacksTask[T](*, loop: asyncio.AbstractEventLoop | None = ...)[source]

Bases: TimeAwareAsyncCallbacksTask[T], EagerAsyncCallbacksTask[T]

A subclass of TimeAwareAsyncCallbacksTask that uses an eager task factory.

class asyncutils.futures.TimeAwareAsyncCallbacksFuture[T](*, loop: asyncio.AbstractEventLoop | None = ...)[source]

Bases: TimeAwareFuture[T], AsyncCallbacksFuture[T]

A subclass of AsyncCallbacksFuture that can be compared to other TimeAwareAsyncCallbacksFuture’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 AsyncCallbacksTask that can be compared to other TimeAwareAsyncCallbacksTask’s based on the time they were created.

class asyncutils.futures.TimeAwareFuture[T][source]

Bases: asyncio.Future[T]

A subclass of Future that can be compared to other TimeAwareFuture’s based on the time they were created.

__lt__(other: Self, /) bool
class asyncutils.futures.TimeAwareTask[T][source]

Bases: asyncio.Task[T]

A subclass of Task that can be compared to other TimeAwareTask’s based on the time they were created.

__lt__(other: Self, /) bool