Fix getUser binding loops & coro race conditions
This commit is contained in:
@@ -37,32 +37,31 @@ class App:
|
||||
return asyncio.run_coroutine_threadsafe(coro, self.loop)
|
||||
|
||||
|
||||
def _call_coro(self, coro: Coroutine) -> str:
|
||||
uuid = str(uuid4())
|
||||
|
||||
def _call_coro(self, coro: Coroutine, uuid: str) -> None:
|
||||
self.run_in_loop(coro).add_done_callback(
|
||||
lambda future: CoroutineDone(uuid=uuid, result=future.result())
|
||||
)
|
||||
return uuid
|
||||
|
||||
|
||||
def call_backend_coro(self,
|
||||
name: str,
|
||||
uuid: str,
|
||||
args: Optional[List[str]] = None,
|
||||
kwargs: Optional[Dict[str, Any]] = None) -> str:
|
||||
return self._call_coro(
|
||||
getattr(self.backend, name)(*args or [], **kwargs or {})
|
||||
kwargs: Optional[Dict[str, Any]] = None) -> None:
|
||||
self._call_coro(
|
||||
getattr(self.backend, name)(*args or [], **kwargs or {}), uuid
|
||||
)
|
||||
|
||||
|
||||
def call_client_coro(self,
|
||||
account_id: str,
|
||||
name: str,
|
||||
uuid: str,
|
||||
args: Optional[List[str]] = None,
|
||||
kwargs: Optional[Dict[str, Any]] = None) -> str:
|
||||
kwargs: Optional[Dict[str, Any]] = None) -> None:
|
||||
client = self.backend.clients[account_id]
|
||||
return self._call_coro(
|
||||
getattr(client, name)(*args or [], **kwargs or {})
|
||||
self._call_coro(
|
||||
getattr(client, name)(*args or [], **kwargs or {}), uuid
|
||||
)
|
||||
|
||||
|
||||
|
@@ -24,6 +24,8 @@ class Backend:
|
||||
self.past_tokens: Dict[str, str] = {} # {room_id: token}
|
||||
self.fully_loaded_rooms: Set[str] = set() # {room_id}
|
||||
|
||||
self.pending_profile_requests: Set[str] = set()
|
||||
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"{type(self).__name__}(clients={self.clients!r})"
|
||||
|
@@ -110,6 +110,10 @@ class MatrixClient(nio.AsyncClient):
|
||||
|
||||
|
||||
async def request_user_update_event(self, user_id: str) -> None:
|
||||
if user_id in self.backend.pending_profile_requests:
|
||||
return
|
||||
self.backend.pending_profile_requests.add(user_id)
|
||||
|
||||
print("Requesting user profile:", user_id)
|
||||
response = await self.get_profile(user_id)
|
||||
|
||||
@@ -123,6 +127,8 @@ class MatrixClient(nio.AsyncClient):
|
||||
status_message = "", # TODO
|
||||
)
|
||||
|
||||
self.backend.pending_profile_requests.discard(user_id)
|
||||
|
||||
|
||||
@property
|
||||
def all_rooms(self) -> Dict[str, MatrixRoom]:
|
||||
|
Reference in New Issue
Block a user