From 92b7be965669c16b7232d4fb4240935cf6b20d27 Mon Sep 17 00:00:00 2001 From: Emmanuel Leblond Date: Tue, 24 Dec 2024 02:36:54 +0100 Subject: [PATCH] Remove useless `isinstance` in server `BaseEventsComponent` --- server/parsec/components/events.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/server/parsec/components/events.py b/server/parsec/components/events.py index f279d4dc17f..491f72f419f 100644 --- a/server/parsec/components/events.py +++ b/server/parsec/components/events.py @@ -440,17 +440,19 @@ async def sse_api_events_listen( outcome = await self._register_client( client_ctx=client_ctx, last_event_id=last_event_id, cancel_scope=cancel_scope ) + match outcome: + case (initial_organization_config_event, channel_receiver, registered_client): + pass + case SseAPiEventsListenBadOutcome() as error: + yield error + return + try: - match outcome: - case (initial_organization_config_event, channel_receiver, registered_client): - # Make sure to close the sender when leaving this scope - # This way, the receiver gets notified with an `anyio.EndOfStream` - with registered_client.channel_sender: - yield (initial_organization_config_event, channel_receiver) - case SseAPiEventsListenBadOutcome() as error: - yield error + # Make sure to close the sender when leaving this scope + # This way, the receiver gets notified with an `anyio.EndOfStream` + with registered_client.channel_sender: + yield (initial_organization_config_event, channel_receiver) finally: - if not isinstance(outcome, SseAPiEventsListenBadOutcome): - # It's vital to unregister the client here given the memory location of the - # client (and hence the id resulting of it) will most likely be re-used ! - self._registered_clients.pop(id(client_ctx)) + # It's vital to unregister the client here given the memory location of the + # client (and hence the id resulting of it) will most likely be re-used ! + self._registered_clients.pop(id(client_ctx))