Deleted unused timeout logic
parent
a6e921548b
commit
18e4352faf
|
@ -178,9 +178,6 @@ async def open_jsonrpc_session(
|
||||||
request_type: Optional[type] = None,
|
request_type: Optional[type] = None,
|
||||||
request_hook: Optional[Callable] = None,
|
request_hook: Optional[Callable] = None,
|
||||||
error_hook: Optional[Callable] = None,
|
error_hook: Optional[Callable] = None,
|
||||||
timeout: int = 5,
|
|
||||||
timeout_hook: Optional[Callable] = None,
|
|
||||||
timeout_args: list = [],
|
|
||||||
) -> Callable[[str, dict], dict]:
|
) -> Callable[[str, dict], dict]:
|
||||||
|
|
||||||
async with (
|
async with (
|
||||||
|
@ -226,48 +223,41 @@ 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.
|
also recieves responses to requests originated from the server side.
|
||||||
reconnects the tasks after timeout.
|
|
||||||
'''
|
'''
|
||||||
with trio.move_on_after(timeout) as cancel_scope:
|
|
||||||
async for msg in ws:
|
|
||||||
match msg:
|
|
||||||
case {
|
|
||||||
'result': result,
|
|
||||||
'id': mid,
|
|
||||||
} if res_entry := rpc_results.get(mid):
|
|
||||||
|
|
||||||
res_entry['result'] = response_type(**msg)
|
async for msg in ws:
|
||||||
res_entry['event'].set()
|
match msg:
|
||||||
|
case {
|
||||||
|
'result': result,
|
||||||
|
'id': mid,
|
||||||
|
} if res_entry := rpc_results.get(mid):
|
||||||
|
|
||||||
case {
|
res_entry['result'] = response_type(**msg)
|
||||||
'result': _,
|
res_entry['event'].set()
|
||||||
'id': mid,
|
|
||||||
} if not rpc_results.get(mid):
|
|
||||||
log.warning(f'Wasn\'t expecting ws msg: {json.dumps(msg, indent=4)}')
|
|
||||||
|
|
||||||
case {
|
case {
|
||||||
'method': _,
|
'result': _,
|
||||||
'params': _,
|
'id': mid,
|
||||||
}:
|
} if not rpc_results.get(mid):
|
||||||
log.debug(f'Recieved\n{msg}')
|
log.warning(f'Wasn\'t expecting ws msg: {json.dumps(msg, indent=4)}')
|
||||||
if request_hook:
|
|
||||||
await request_hook(request_type(**msg))
|
|
||||||
|
|
||||||
case {
|
case {
|
||||||
'error': error
|
'method': _,
|
||||||
}:
|
'params': _,
|
||||||
log.warning(f'Recieved\n{error}')
|
}:
|
||||||
if error_hook:
|
log.debug(f'Recieved\n{msg}')
|
||||||
await error_hook(response_type(**msg))
|
if request_hook:
|
||||||
|
await request_hook(request_type(**msg))
|
||||||
|
|
||||||
case _:
|
case {
|
||||||
log.warning(f'Unhandled JSON-RPC msg!?\n{msg}')
|
'error': error
|
||||||
|
}:
|
||||||
|
log.warning(f'Recieved\n{error}')
|
||||||
|
if error_hook:
|
||||||
|
await error_hook(response_type(**msg))
|
||||||
|
|
||||||
if cancel_scope.cancelled_caught:
|
case _:
|
||||||
await ws._connect()
|
log.warning(f'Unhandled JSON-RPC msg!?\n{msg}')
|
||||||
n.start_soon(recv_task)
|
|
||||||
if timeout_hook:
|
|
||||||
n.start_soon(timeout_hook, json_rpc, *timeout_args)
|
|
||||||
|
|
||||||
|
|
||||||
n.start_soon(recv_task)
|
n.start_soon(recv_task)
|
||||||
|
|
Loading…
Reference in New Issue