Re: [Cppcms-users] How to fullfill ajax-call from different thread?
Brought to you by:
artyom-beilis
From: eric m. <mid...@gm...> - 2016-02-21 09:12:53
|
Hi Artyom, Thanks for clarifying. To answer your question: I have a thread that controls a motor and another thread that services a webinterface. I send a command from the webthread to the motorthread via an ajax-call and that has to be asynchronous otherwise it will not respond to input from the user. Meanwhile the motorthread starts doing its thing and that can take a while but it has to report back status to the user. I now use two asynchronous ajax-calls: one for receiving the status from the motorthread that waits for it and another one to send the command to the motorthread that returns immediately. When I asked the question my intention was to report back with using the second ajax-call for receiving the status from the motorthread. There's another thing I'm wondering about. Given the ticker_example: is it possible to have two independent streams under the same endpoint, say /ticker/stream1 and /ticker/stream2 and if yes how would I do that? Kind regards, Eric On Tue, Feb 16, 2016 at 2:02 AM, Artyom Beilis <art...@gm...> wrote: > > Taking the json_rpc_chat example as a starting point, is it possible to > > respond to get() from another thread? Let me elaborate a bit on that. > > > > In the chat example the get activates a callback that is called by a post > > from the browser via the broadcast method. Is it possible to let this > > callback be called by a different server-thread that is performing a task > > and comes back with the result to be returned to the original get > activated > > by the browser? > > > > To put it differently, is it possible to interact with the > json_rpc_server > > and fullfill callbacks from outside? > > > > Reason for asking is that I'm using ajax-calls to perform tasks on the > > server but I do not want the browser to hang up on it while waiting for > the > > result. > > > > Kind regards, > > Eric > > > > > To be honest I don't clearly understand what are you trying to do. > > You have two types of applications: > > 1. Synchronous - running in threads and returning result immediately > 2. Asynchronous - running in a single event loop - that can postpone > the response or keep long running open connections if needed. > > You can "send" messages from synchronous apps (or what ever thread) > to asynchronous apps by posting callbacks to the main > event loop - i.e. service().post(some_function) such that this > "some_function" would be executed in the event loop and can interact > with the async apps. > > So for example you can have a generic thread that posts every minute a > message to the chat from some thread > using this callback method. > > > Artyom > > > > > > ------------------------------------------------------------------------------ > > Site24x7 APM Insight: Get Deep Visibility into Application Performance > > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > > Monitor end-to-end web transactions and take corrective actions now > > Troubleshoot faster and improve end-user experience. Signup Now! > > http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 > > _______________________________________________ > > Cppcms-users mailing list > > Cpp...@li... > > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > -- Groetjes, Eric http://www.lightandmagicphotography.nl http://www.lightandmagicphotography.com |