Astn/JSON-RPC.NET

Synchronous handling

hovi opened this issue · 4 comments

hovi commented

Hi,

I am trying to use your library to control a game. TCP server is collecting JSON requests in into queue, which are then handled in game loop in it's own thread, which is different to the thread for collecting incoming data. So what I need is to handle requests from the queue synchronously and in my own thread, otherwise I am running into race conditions and game is crashing randomly.

I am not C# developer and I don't have much knowledge of the library, but I was able to achieve what I need by basically using JsonRpcProcessor.ProcessInternal, since that method is synchronous, returning just string. But since the method is private (and some of methods in that method), I couldn't use it directly. I had to copy and modify it and run my own version.

So please correct me if my approach is incorrect.

  • Couldn't this private method ProcessInternal be renamed to ProcessSync or something similar and made public?
  • Is there any specific reason why it's private?
  • If I am mistaken, what is correct way to call the library passing request JSON string and getting response JSON in same thread synchronously?

Cheers!

Astn commented

You are correct, there is nothing preventing ProcessInternal from being made public. Or creating a function such as ProcessSync that calls it.
If you want to do so I'm accepting pull requests.

Astn commented

@hovi I've make that function ProcessSync public for you. 177be60

Astn commented

This is published it to nuget as of version 1.2.3 @ 177be60