Skip to content

Commit

Permalink
feat(#267): Fixed evil race condition in bs_rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
lxgr-linux committed Nov 12, 2024
1 parent c47976d commit e520121
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions bs_rpc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import logging
import threading
import time

Expand Down Expand Up @@ -48,19 +47,19 @@ def __new_call_id(self):
return call_id

def call_for_response(self, body: Body) -> Body:
call_id = self.__new_call_id()
ch = Channel()
self.__send(body, call_id, Method.CALL_FOR_RESPONSE)
call_id = self.__new_call_id()
self.calls[call_id] = ch
self.__send(body, call_id, Method.CALL_FOR_RESPONSE)
call = ch.listen()
del self.calls[call_id]
return call

def call_for_responses(self, body: Body) -> ChannelGenerator:
call_id = self.__new_call_id()
ch = Channel()
self.__send(body, call_id, Method.CALL_FOR_RESPONSES)
call_id = self.__new_call_id()
self.calls[call_id] = ch
self.__send(body, call_id, Method.CALL_FOR_RESPONSES)

def close_fn():
del self.calls[call_id]
Expand Down

0 comments on commit e520121

Please sign in to comment.