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 committed 2021-06-28 12:45:50 -04:00
1 parent 00f4bd594f
commit ecc0fbdae9
1 file changed
+6 -4
+6 -4
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()