Skip to content

Commit

Permalink
Add NEWS and docs for eager task factory
Browse files Browse the repository at this point in the history
  • Loading branch information
itamaro committed Mar 20, 2023
1 parent 6975183 commit bcf40dc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Doc/library/asyncio-task.rst
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,30 @@ Running Tasks Concurrently
and there is no running event loop.


Eager Task Factory
==================

.. function:: eager_task_factory(loop, coro, *, name=None, context=None)

A task factory for eager task execution.

When using this factory (via ``loop.set_task_factory(asyncio.eager_task_factory)``),
coroutines that are able to complete synchronously (without suspending)
are returned immediately as a completed :class:`Future`.

A regular :class:`Task` is returned otherwise, at the first suspension of *coro*.

.. versionadded:: 3.12

.. function:: create_eager_task_factory(custom_task_constructor)

Create an eager task factory, similar to :func:`eager_task_factory`,
using the provided *custom_task_constructor* when creating a new task instead
of the default :class:`Task`.

.. versionadded:: 3.12


Shielding From Cancellation
===========================

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Implemented an eager task factory in asyncio. When set as a task factory on
an event loop, it performs eager execution of coroutines and returns a
completed future instead of scheduling a task to the event loop if the
coroutine can complete without suspending.

0 comments on commit bcf40dc

Please sign in to comment.