explodinglabs / jsonrpcserver

Process incoming JSON-RPC requests in Python
https://www.jsonrpcserver.com
MIT License
185 stars 40 forks source link

Blocking task with status callbacks #263

Closed lolsborn closed 1 year ago

lolsborn commented 1 year ago

I am trying to have an RPC method that will create a resource an on success return a response with the correct rpc id. In the meantime I want it to send status notifications for that resource based on a callback provided by a third-party library.

Here is a minimal example: https://gist.github.com/lolsborn/2a4e00a64c830a43a7ccbdd554f39831

The issue I'm having is the callback method is not async, but I need to call websocket.send() which is asynchronous. I've tried a lot of ways to get this to work, but have been stuck for sometime and would appreciate any insights you might have.

bcb commented 1 year ago

Hi @lolsborn (keep in mind I am not an asyncio expert) - any reason blocking_with_callback can't be async? I had success with your code once that was made async.

lolsborn commented 1 year ago

Hey Beau, thanks for taking a look at this, it's really my issue not not related to jsonrpcserver I think so I'll close it. We ended up not using jsonrpc just because we have a lot of streaming responses and currently the spec / libraries don't really support methods with multiple responses in the way we wish to architect things.

The blocking_with_callback call here is representing a third-party library so it couldn't be reasonably made async.