Backend: separate wait_until_(any_?)client_exists()

This commit is contained in:
miruka 2019-11-04 06:56:26 -04:00
parent e1600389fc
commit 337603595a

View File

@ -108,13 +108,18 @@ class Backend:
await self.saved_accounts.delete(user_id) await self.saved_accounts.delete(user_id)
async def wait_until_client_exists(self, user_id: str = "") -> None: async def wait_until_any_client_exists(self) -> None:
loops = 0
while True: while True:
if user_id and user_id in self.clients: if self.clients:
return return
if not user_id and self.clients: await asyncio.sleep(0.1)
async def wait_until_client_exists(self, user_id: str) -> None:
loops = 0
while True:
if user_id in self.clients:
return return
if loops and loops % 100 == 0: # every 10s except first time if loops and loops % 100 == 0: # every 10s except first time
@ -171,7 +176,7 @@ class Backend:
async with self.get_profile_locks[user_id]: async with self.get_profile_locks[user_id]:
if not self.clients: if not self.clients:
await self.wait_until_client_exists() await self.wait_until_any_client_exists()
client = self.clients.get( client = self.clients.get(
user_id, user_id,