|
|
@ -59,21 +59,21 @@ class AsyncSimpleClient: |
|
|
|
self.input_event.clear() |
|
|
|
self.client = AsyncClient(*self.client_args, **self.client_kwargs) |
|
|
|
|
|
|
|
@self.client.event |
|
|
|
@self.client.event(namespace=self.namespace) |
|
|
|
def connect(): # pragma: no cover |
|
|
|
self.connected = True |
|
|
|
self.connected_event.set() |
|
|
|
|
|
|
|
@self.client.event |
|
|
|
@self.client.event(namespace=self.namespace) |
|
|
|
def disconnect(): # pragma: no cover |
|
|
|
self.connected_event.clear() |
|
|
|
|
|
|
|
@self.client.event |
|
|
|
@self.client.event(namespace=self.namespace) |
|
|
|
def __disconnect_final(): # pragma: no cover |
|
|
|
self.connected = False |
|
|
|
self.connected_event.set() |
|
|
|
|
|
|
|
@self.client.on('*') |
|
|
|
@self.client.on('*', namespace=self.namespace) |
|
|
|
def on_event(event, *args): # pragma: no cover |
|
|
|
self.input_buffer.append([event, *args]) |
|
|
|
self.input_event.set() |
|
|
@ -172,8 +172,12 @@ class AsyncSimpleClient: |
|
|
|
the server included arguments with the event, they are returned as |
|
|
|
additional list elements. |
|
|
|
""" |
|
|
|
if not self.input_buffer: |
|
|
|
await self.connected_event.wait() |
|
|
|
while not self.input_buffer: |
|
|
|
try: |
|
|
|
await asyncio.wait_for(self.connected_event.wait(), |
|
|
|
timeout=timeout) |
|
|
|
except asyncio.TimeoutError: # pragma: no cover |
|
|
|
raise TimeoutError() |
|
|
|
if not self.connected: |
|
|
|
raise DisconnectedError() |
|
|
|
try: |
|
|
@ -189,5 +193,13 @@ class AsyncSimpleClient: |
|
|
|
|
|
|
|
Note: this method is a coroutine. |
|
|
|
i """ |
|
|
|
if self.connected: |
|
|
|
await self.client.disconnect() |
|
|
|
self.client = None |
|
|
|
self.connected = False |
|
|
|
|
|
|
|
async def __aenter__(self): |
|
|
|
return self |
|
|
|
|
|
|
|
async def __aexit__(self, exc_type, exc_val, exc_tb): |
|
|
|
await self.disconnect() |
|
|
|