WApplication::bind() usage in combination with Wt::WServer::post
Added by Markus Klemm over 10 years ago
I guess you guys/gals don't like cross-posting but since the Wt hasn't so much audience and I don't want to take the opportunity to get some reputation points from you:
http://stackoverflow.com/q/32718414/3537677
Of course you can answer here, if you prefer.
(Short version below):
I want to bind a callback, which will be called by a thread outside the Wt event loop. So obviously I want to use Wt::WServer::post, but I don't get how WApplication::bind should be used, since it's a nonstatic function. First attempt was this:
auto loaded_callback = [](const decltype(Wt::WApplication::sessionId) &session){
Wt::WServer::post(session,
Wt::WApplication::bind(&table_model::member_func),)
};
Which of course didn't work because bind is nonstatic. However my next attempt
auto object_protect_bind =
Wt::WApplication::instance()->bind(&order_aggregate_table_model::load_future_in_map);
failed with a shitload of compiler errors
Replies (2)
RE: WApplication::bind() usage in combination with Wt::WServer::post - Added by Koen Deforche over 10 years ago
Hey,
Have a look at the broadcast example:
https://github.com/kdeforche/wt/blob/master/examples/feature/broadcast/BroadCast.C
It would typically defeat the purpose of WApplication::bind() to get called at the same time as WServer::post(). You will call WApplication::bind() when you export the 'callback' from your application to some other place, to be posted later.
Koen
RE: WApplication::bind() usage in combination with Wt::WServer::post - Added by Markus Klemm over 10 years ago
Ah the crucial part is that Wt::WApplication::bind
needs the this pointer! This should really be noted in the documentation, where it just states "template bind (const F &f)"
is supposed to take the already binded method, not the method itself, misunderstood that from the part This function wraps such an object method out of the documentation.
Of course now this makes sense, because it couldn't work the other way, but I didn't get that until now. Template errors are best errors.
Thank you very much!