Skip to content

Commit

Permalink
add Client.wait_until_ready (#1)
Browse files Browse the repository at this point in the history
* add Client.wait_until_ready

* add missing future import
  • Loading branch information
circuitsacul authored Dec 8, 2022
1 parent e896fdc commit 1c8e060
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion example/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@


async def send(client: Client) -> None:
await client.wait_until_ready()
while True:
await asyncio.sleep(5)
await client.send(Message(data="hi"), client.clients)
await asyncio.sleep(1)


async def main(client: Client) -> None:
Expand Down
2 changes: 2 additions & 0 deletions example/events.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from socketapp import Client, Event, Server


Expand Down
4 changes: 4 additions & 0 deletions socketapp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def __init__(
def uri(self) -> str:
return f"ws://{self.host}:{self.port}"

async def wait_until_ready(self) -> None:
while self.ws is None and self.future and not self.future.done():
await asyncio.sleep(0.25)

async def run(self) -> None:
asyncio.get_event_loop().add_signal_handler(signal.SIGINT, self.stop)

Expand Down

0 comments on commit 1c8e060

Please sign in to comment.