Replaced try/except block in recv_task() by match msg, and added new changes to description comment

dark_clearing_improvements
Esmeralda Gallardo 2022-10-19 15:38:35 -03:00
parent db0b59abaa
commit 3f5dec82ed
No known key found for this signature in database
GPG Key ID: AD67FBB417CAC71B
1 changed files with 20 additions and 15 deletions

View File

@ -221,28 +221,33 @@ async def open_jsonrpc_session(
''' '''
receives every ws message and stores it in its corresponding result receives every ws message and stores it in its corresponding result
field, then sets the event to wakeup original sender tasks. field, then sets the event to wakeup original sender tasks.
also, recieves responses to requests originated from the server side.
''' '''
async for msg in ws: async for msg in ws:
try: match msg:
msg = response_type(**msg) case {
'result': _
}:
msg = response_type(**msg)
if msg.id not in rpc_results: if msg.id not in rpc_results:
log.warning(f'Wasn\'t expecting ws msg: {json.dumps(msg, indent=4)}') log.warning(f'Wasn\'t expecting ws msg: {json.dumps(msg, indent=4)}')
res = rpc_results.setdefault( res = rpc_results.setdefault(
msg.id, msg.id,
{'result': None, 'event': trio.Event()} {'result': None, 'event': trio.Event()}
) )
res['result'] = msg res['result'] = msg
res['event'].set() res['event'].set()
except TypeError: case {
if request_type == None: 'method': _,
raise 'params': _
await request_hook(request_type(**msg)) }:
if request_hook:
await request_hook(request_type(**msg))
n.start_soon(recv_task) n.start_soon(recv_task)