Skip to content

Commit 520beaa

Browse files
committed
Make wait() private
We don't really need to make it a public method, as one can just use `await service` to await for it. It is still good to have it separate as implementing `__await__` is easier based on another awaitable. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 0f4ca6b commit 520beaa

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/frequenz/core/asyncio.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ async def stop(self, msg: str | None = None) -> None:
401401
return
402402
self.cancel(msg)
403403
try:
404-
await self.wait()
404+
await self
405405
except BaseExceptionGroup as exc_group:
406406
# We want to ignore CancelledError here as we explicitly cancelled all the
407407
# tasks.
@@ -441,7 +441,7 @@ async def __aexit__(
441441
"""
442442
await self.stop()
443443

444-
async def wait(self) -> None:
444+
async def _wait(self) -> None:
445445
"""Wait for this service to finish.
446446
447447
Wait until all the service tasks are finished.
@@ -483,7 +483,7 @@ def __await__(self) -> collections.abc.Generator[None, None, None]:
483483
Returns:
484484
An implementation-specific generator for the awaitable.
485485
"""
486-
return self.wait().__await__()
486+
return self._wait().__await__()
487487

488488
def __del__(self) -> None:
489489
"""Destroy this instance.

tests/test_asyncio.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ async def test_start_stop() -> None:
110110
assert fake_service.is_running is False
111111

112112

113-
@pytest.mark.parametrize("method", ["await", "wait", "stop"])
113+
@pytest.mark.parametrize("method", ["await", "stop"])
114114
async def test_start_and_crash(
115-
method: Literal["await"] | Literal["wait"] | Literal["stop"],
115+
method: Literal["await"] | Literal["stop"],
116116
) -> None:
117117
"""Test a service reports when crashing."""
118118
exc = RuntimeError("error")
@@ -125,8 +125,6 @@ async def test_start_and_crash(
125125
match method:
126126
case "await":
127127
await fake_service
128-
case "wait":
129-
await fake_service.wait()
130128
case "stop":
131129
# Give the service some time to run and crash, otherwise stop() will
132130
# cancel it before it has a chance to crash

0 commit comments

Comments
 (0)