flpit 0.2.1.dev6__py3-none-any.whl → 0.2.1.dev7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- flpit/task.py +35 -2
- {flpit-0.2.1.dev6.dist-info → flpit-0.2.1.dev7.dist-info}/METADATA +1 -1
- {flpit-0.2.1.dev6.dist-info → flpit-0.2.1.dev7.dist-info}/RECORD +5 -5
- {flpit-0.2.1.dev6.dist-info → flpit-0.2.1.dev7.dist-info}/WHEEL +0 -0
- {flpit-0.2.1.dev6.dist-info → flpit-0.2.1.dev7.dist-info}/licenses/LICENSE +0 -0
flpit/task.py
CHANGED
|
@@ -599,7 +599,7 @@ class Task(Generic[T]):
|
|
|
599
599
|
Accepts Task instances and raw awaitables (including coroutine objects)
|
|
600
600
|
positionally or in one iterable. Raw awaitables are scheduled
|
|
601
601
|
automatically. The winning task is returned even if it failed or was
|
|
602
|
-
|
|
602
|
+
canceled; inspect/await that task to observe
|
|
603
603
|
its outcome. Losing tasks continue running. An empty input is invalid.
|
|
604
604
|
If multiple tasks are already complete at observation time, input order
|
|
605
605
|
breaks the tie deterministically.
|
|
@@ -612,6 +612,22 @@ class Task(Generic[T]):
|
|
|
612
612
|
cls.run(_when_any_coroutine, normalized, name=name, token=token),
|
|
613
613
|
)
|
|
614
614
|
|
|
615
|
+
@staticmethod
|
|
616
|
+
async def collect(*tasks: Task[Any] | list[Task[Any]]):
|
|
617
|
+
"""
|
|
618
|
+
Yields tasks as they complete. Accepts either a list or loose positional tasks.
|
|
619
|
+
"""
|
|
620
|
+
# FIX: If it's a list or tuple, extract and cast the FIRST element to a mutable list
|
|
621
|
+
if len(tasks) == 1 and isinstance(tasks[0], (list, tuple)):
|
|
622
|
+
pending = list(tasks[0]) # Converts the inner container into a fresh list
|
|
623
|
+
else:
|
|
624
|
+
pending = list(tasks) # Converts the *tasks tuple into a fresh list
|
|
625
|
+
|
|
626
|
+
while pending:
|
|
627
|
+
finished_task = await Task.when_any(pending)
|
|
628
|
+
pending.remove(finished_task) # Safe to call, because pending is ALWAYS a list!
|
|
629
|
+
yield finished_task
|
|
630
|
+
|
|
615
631
|
@classmethod
|
|
616
632
|
def delay(
|
|
617
633
|
cls,
|
|
@@ -1574,4 +1590,21 @@ def task(async_function: Callable[..., Any]) -> Callable[..., Task[Any]]:
|
|
|
1574
1590
|
def wrapper(*args: Any, **kwargs: Any) -> Task[Any]:
|
|
1575
1591
|
return Task.run(async_function, *args, **kwargs)
|
|
1576
1592
|
|
|
1577
|
-
return wrapper
|
|
1593
|
+
return wrapper
|
|
1594
|
+
|
|
1595
|
+
|
|
1596
|
+
def coro_task(async_function: Callable[..., Any]) -> Callable[..., Task[Any]]:
|
|
1597
|
+
"""
|
|
1598
|
+
| Wraps an async coroutine function to be compatible with Task.run(coro)
|
|
1599
|
+
|
|
1600
|
+
Use with caution as this transfers execution control to an isolated asyncio loop runner.
|
|
1601
|
+
"""
|
|
1602
|
+
import asyncio
|
|
1603
|
+
@functools.wraps(async_function)
|
|
1604
|
+
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
1605
|
+
with asyncio.Runner() as runner:
|
|
1606
|
+
# Call the function with its arguments to generate the Coroutine object instance
|
|
1607
|
+
coro = async_function(*args, **kwargs)
|
|
1608
|
+
return runner.run(coro)
|
|
1609
|
+
|
|
1610
|
+
return task(wrapper)
|
|
@@ -3,10 +3,10 @@ flpit/__init__.py,sha256=tx4tkpLxoKQTP7wu2PyUtQtLs9_pWHbx1jHh4Vdsrus,1275
|
|
|
3
3
|
flpit/flp.py,sha256=i-FbnMeO92cxNRssYsgdlm2UGjILpveXgYUT468fWvY,999
|
|
4
4
|
flpit/json.py,sha256=HYuZl_xLUTacsUusCct0PYhC0s2iVYghjTggay4ehjI,19210
|
|
5
5
|
flpit/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
flpit/task.py,sha256=
|
|
6
|
+
flpit/task.py,sha256=zeaAbyIbuCNER-eO9MyOEOXD75EekhM3zWqZoVQHDEw,62183
|
|
7
7
|
flpit/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
8
|
flpit/core/linq.py,sha256=USO-L0z54pXcq-71j6kKzzFp0clHDMBRuhxOTC9XrdY,41468
|
|
9
|
-
flpit-0.2.1.
|
|
10
|
-
flpit-0.2.1.
|
|
11
|
-
flpit-0.2.1.
|
|
12
|
-
flpit-0.2.1.
|
|
9
|
+
flpit-0.2.1.dev7.dist-info/METADATA,sha256=iQsBVwrrTsJlpjEJAgSEvK9KsFDvM_FVRJpBpvpYKow,13098
|
|
10
|
+
flpit-0.2.1.dev7.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
11
|
+
flpit-0.2.1.dev7.dist-info/licenses/LICENSE,sha256=bi5Vg_YP3Oq3jaOMQT4b7WZu0NfBcZr-nRyOExUKJrQ,1063
|
|
12
|
+
flpit-0.2.1.dev7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|