diff --git a/README.md b/README.md index bd166bfe..2fee5f03 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ Or using the context manager, for finer control: ```python async with restate.with_connection(app, name="greeter-v1") as connection: print(connection.info.deployment_url) - await connection.wait() + await connection.wait_closed() ``` ### Clients diff --git a/python/restate/connection.py b/python/restate/connection.py index 9ae615e9..d82674cd 100644 --- a/python/restate/connection.py +++ b/python/restate/connection.py @@ -24,6 +24,7 @@ import signal import sys import typing +import warnings from contextlib import asynccontextmanager from restate.server_types import RestateAppT @@ -66,7 +67,7 @@ def info(self) -> TunnelInfo: """Metadata from the first successful handshake (``deployment_url``, ``proxy_url``, …).""" return self._info - async def wait(self) -> None: + async def wait_closed(self) -> None: """ Wait until the connection stops serving: returns after :meth:`shutdown`, raises :class:`ConnectError` when the connection failed for good (rejected credentials, @@ -74,12 +75,26 @@ async def wait(self) -> None: """ await self._engine.terminated() + async def wait(self) -> None: + """ + Deprecated alias of :meth:`wait_closed`. + + .. deprecated:: 1.4.0 + Use :meth:`wait_closed` instead. + """ + warnings.warn( + "Connection.wait() is deprecated, use Connection.wait_closed() instead", + DeprecationWarning, + stacklevel=2, + ) + await self.wait_closed() + async def shutdown(self, grace: float = 0.0) -> None: """ Stop serving. New invocations are refused and Restate Cloud is told; in-flight invocations get ``grace`` seconds to finish before the connections are cut. ``0`` cuts them at once. Never raises: a connection that already failed reports - its error through :meth:`wait`, not here. + its error through :meth:`wait_closed`, not here. """ try: await self._engine.shutdown(grace) @@ -119,7 +134,7 @@ async def with_connection( async with restate.with_connection(app, name="greeter") as connection: print(connection.info.deployment_url) - await connection.wait() + await connection.wait_closed() """ options = TunnelEngineOptions.resolve(name=name, key=key) engine = TunnelEngine(app, options) @@ -199,4 +214,4 @@ def on_signal() -> None: file=sys.stderr, flush=True, ) - await connection.wait() + await connection.wait_closed() diff --git a/tests/connect.py b/tests/connect.py index a1588cb6..75e1a0fb 100644 --- a/tests/connect.py +++ b/tests/connect.py @@ -823,7 +823,7 @@ async def run() -> None: assert conn.info.name == TUNNEL_NAME response = await cloud.request("/http/h/9080/discover", identity_headers("/discover")) assert response.status == 200 - waiter = asyncio.ensure_future(conn.wait()) + waiter = asyncio.ensure_future(conn.wait_closed()) await asyncio.sleep(0.05) assert not waiter.done() await conn.shutdown(0.0)