Skip to content

Commit 245a52b

Browse files
committed
Add NEWS and docs for eager task factory
1 parent 71eeda4 commit 245a52b

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Doc/library/asyncio-task.rst

+24
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,30 @@ Running Tasks Concurrently
518518
and there is no running event loop.
519519

520520

521+
Eager Task Factory
522+
==================
523+
524+
.. function:: eager_task_factory(loop, coro, *, name=None, context=None)
525+
526+
A task factory for eager task execution.
527+
528+
When using this factory (via ``loop.set_task_factory(asyncio.eager_task_factory)``),
529+
coroutines that are able to complete synchronously (without suspending)
530+
are returned immediately as a completed :class:`Future`.
531+
532+
A regular :class:`Task` is returned otherwise, at the first suspension of *coro*.
533+
534+
.. versionadded:: 3.12
535+
536+
.. function:: create_eager_task_factory(custom_task_constructor)
537+
538+
Create an eager task factory, similar to :func:`eager_task_factory`,
539+
using the provided *eager_task_factory* when creating a new task instead
540+
of the default :class:`Task`.
541+
542+
.. versionadded:: 3.12
543+
544+
521545
Shielding From Cancellation
522546
===========================
523547

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

0 commit comments

Comments
 (0)