You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 10, 2018. It is now read-only.
Repository navigation
This repository was archived by the owner on May 10, 2018. It is now read-only.
I am trying to understand how WampSharp uses threads / how it can be used in multii-threaded applications, but fail to find any documentation on that issues. To be specific, the following questions remain open so far:
Is it safe to use a channel from multiple threads as a caller (using e.g. GetCalleeProxy?
When I register a callee, is the method it defined always run in a separate thread? If, for example, it takes 5 seconds to compute, and two callers call it simultaneously – will it take 5 seconds or 10?
How does this behavior depend on whether the callee's WampProcedures are defined as returning a Task<resultType> instead of <resultType>?
This depends whether the method is synchronous (i.e. doesn't return a Task) or asynchronous (returns a Task). In the first case, the method blocks the WebSocket loop, and other requests can't be handled. Therefore it will take 10 seconds to complete both requests in this case. In the latter case, where the method returns a Task, the Task is awaited. In this case, once the task is returned, the WebSocket loop is no longer blocked and further requests are processed.
Hi Elad,
thanks for your response. That means, if I want to register methods (callee) that might take some time, I should follow the pattern?
[WampProcedure("com.example.test")]
public async Task<TResult> Test()
{
await Task.Run(() => ExpensiveOperation());
// stuff to evaluate the result
return result;
}
Something like that. You should manage yourself the number of tasks you want to run in parallel. You can use some threading mechanism such as TPL.Dataflow (ActionBlock and etc) in order to have better control on the number of tasks running in parallel.
Hi Elad,
just found that this issue is still open – closing it as everything works very well for me, including sharing a client between several threads. Thanks again!
Activity
darkl commentedon Apr 29, 2016
Hi Michael
Regarding your questions:
Elad
supermihi commentedon May 4, 2016
Hi Elad,
thanks for your response. That means, if I want to register methods (callee) that might take some time, I should follow the pattern?
Michael
darkl commentedon May 4, 2016
Hi Michael,
Something like that. You should manage yourself the number of tasks you want to run in parallel. You can use some threading mechanism such as TPL.Dataflow (ActionBlock and etc) in order to have better control on the number of tasks running in parallel.
Best regards,
Elad
supermihi commentedon Nov 8, 2016
Hi Elad,
just found that this issue is still open – closing it as everything works very well for me, including sharing a client between several threads. Thanks again!