Skip to content

Commit 49f605b

Browse files
committed
Rename gather => all, and make gather an alias
1 parent fc1ba43 commit 49f605b

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

src/dispatch/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
import dispatch.integrations
6-
from dispatch.coroutine import call, gather
6+
from dispatch.coroutine import all, call, gather
77
from dispatch.function import DEFAULT_API_URL, Client
88
from dispatch.id import DispatchID
99
from dispatch.proto import Call, Error, Input, Output
@@ -20,4 +20,5 @@
2020
"Status",
2121
"call",
2222
"gather",
23+
"all",
2324
]

src/dispatch/coroutine.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,19 @@ def call(call: Call) -> Any:
1717
@coroutine
1818
@durable
1919
def gather(*awaitables: Awaitable[Any]) -> list[Any]: # type: ignore[misc]
20+
"""Alias for all."""
21+
return all(*awaitables)
22+
23+
24+
@coroutine
25+
@durable
26+
def all(*awaitables: Awaitable[Any]) -> list[Any]: # type: ignore[misc]
2027
"""Concurrently run a set of coroutines and block until all
2128
results are available. If any coroutine fails with an uncaught
2229
exception, it will be re-raised when awaiting a result here."""
23-
return (yield Gather(awaitables))
30+
return (yield All(awaitables))
2431

2532

2633
@dataclass(slots=True)
27-
class Gather:
34+
class All:
2835
awaitables: tuple[Awaitable[Any], ...]

src/dispatch/scheduler.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from dataclasses import dataclass
55
from typing import Any, Callable, Protocol, TypeAlias
66

7-
from dispatch.coroutine import Gather
7+
from dispatch.coroutine import All
88
from dispatch.error import IncompatibleStateError
99
from dispatch.experimental.durable.function import DurableCoroutine, DurableGenerator
1010
from dispatch.proto import Call, Error, Input, Output
@@ -78,8 +78,8 @@ def value(self) -> Any:
7878

7979

8080
@dataclass(slots=True)
81-
class GatherFuture:
82-
"""A future result of a dispatch.coroutine.gather() operation."""
81+
class AllFuture:
82+
"""A future result of a dispatch.coroutine.all() operation."""
8383

8484
order: list[CoroutineID]
8585
waiting: set[CoroutineID]
@@ -386,11 +386,9 @@ def _run(self, input: Input) -> Output:
386386
state.prev_callers.append(coroutine)
387387
state.outstanding_calls += 1
388388

389-
case Gather():
390-
gather = coroutine_yield
391-
389+
case All():
392390
children = []
393-
for awaitable in gather.awaitables:
391+
for awaitable in coroutine_yield.awaitables:
394392
g = awaitable.__await__()
395393
if not isinstance(g, DurableGenerator):
396394
raise ValueError(
@@ -408,7 +406,7 @@ def _run(self, input: Input) -> Output:
408406
state.ready = children + state.ready
409407

410408
child_ids = [child.id for child in children]
411-
coroutine.result = GatherFuture(
409+
coroutine.result = AllFuture(
412410
order=child_ids, waiting=set(child_ids), results={}
413411
)
414412
state.suspended[coroutine.id] = coroutine

0 commit comments

Comments
 (0)