mqtt: return a boolean in the wait_connection method

Rather than require consumers handle the TimeoutError, handle it directly and return the connection state.

SIgned-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2021-06-28 11:22:12 -04:00
parent 00f4bd594f
commit ecc0fbdae9
1 changed files with 6 additions and 4 deletions

View File

@ -339,10 +339,12 @@ class MQTTClient(APITransport):
break
self.reconnect_task = None
async def wait_connection(self, timeout: Optional[float] = None) -> None:
if self.connect_evt.is_set():
return
await asyncio.wait_for(self.connect_evt.wait(), timeout)
async def wait_connection(self, timeout: Optional[float] = None) -> bool:
try:
await asyncio.wait_for(self.connect_evt.wait(), timeout)
except asyncio.TimeoutError:
return False
return True
def is_connected(self) -> bool:
return self.connect_evt.is_set()