title: WApplication::bind() usage in combination with Wt::WServer::post
body: <p>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:</p>
  
  <pre><code>auto loaded_callback = [](const decltype(Wt::WApplication::sessionId) &amp;session){
      Wt::WServer::post(session, 
  Wt::WApplication::bind(&amp;table_model::member_func),)
  };
  </code></pre>
  
  <p>Which of course didn't work because <code>bind</code> is nonstatic. However my next attempt</p>
  
  <pre><code>auto object_protect_bind = 
  Wt::WApplication::instance()-&gt;bind(&amp;order_aggregate_table_model::load_future_in_map);
  </code></pre>
  
  <p>failed with a shitload of compiler errors </p>
  
  <blockquote>
    <p>Error  153 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   \boost\function\function_template.hpp   922 1   MDDB_Web
    Error  156 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   \boost\function\function_template.hpp   926 1   MDDB_Web
    Error  160 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   \boost\function\function_template.hpp   927 1   MDDB_Web
    Error  150 error C2903: 'apply' : symbol is neither a class template nor a function template   \boost\function\function_template.hpp   922 1   MDDB_Web
    Error  162 error C2825: 'manager_type': must be a class or namespace when followed by '::' \boost\function\function_template.hpp   934 1   MDDB_Web
    Error  154 error C2653: 'handler_type' : is not a class or namespace name  \boost\function\function_template.hpp   926 1   MDDB_Web
    Error  158 error C2653: 'handler_type' : is not a class or namespace name  \boost\function\function_template.hpp   927 1   MDDB_Web
    Error  164 error C2275: 'manager_type' : illegal use of this type as an expression \boost\function\function_template.hpp   934 1   MDDB_Web
    Error  165 error C2146: syntax error : missing '}' before identifier 'manage'  \boost\function\function_template.hpp   934 1   MDDB_Web
    Error  159 error C2146: syntax error : missing ';' before identifier 'manager_type'    \boost\function\function_template.hpp   927 1   MDDB_Web
    Error  155 error C2146: syntax error : missing ';' before identifier 'invoker_type'    \boost\function\function_template.hpp   926 1   MDDB_Web
    Error  152 error C2143: syntax error : missing ';' before '&lt;'  \boost\function\function_template.hpp   922 1   MDDB_Web
    Error  163 error C2039: 'manage' : is not a member of '`global namespace'' \boost\function\function_template.hpp   934 1   MDDB_Web
    Error  151 error C2039: 'apply' : is not a member of 'boost::detail::function::get_invoker0'  \boost\function\function_template.hpp   922 1   MDDB_Web
    Error  166 error C1903: unable to recover from previous error(s); stopping compilation \boost\function\function_template.hpp   934 1   MDDB_Web</p>
  </blockquote>
  
  <p>while the overall solution I had in mind was:</p>
  
  <pre><code>auto sessionId = Wt::WApplication::instance()-&gt;sessionId();
  auto server_ptr = Wt::WServer::instance();
  
  auto object_protect_bind = Wt::WApplication::instance()-&gt;bind(&amp;order_aggregate_table_model::load_future_in_map);
  auto inner_bind = std::bind(object_protect_bind, this);
  auto loaded_callback = [] 
      (Wt::WServer* server,
      const std::string &amp;session,
      boost::function&lt;void()&gt; widget_bind)
  -&gt; void {
      server-&gt;post(session, widget_bind, boost::function&lt;void()&gt;());
  };
  
  this-&gt;data_future =
      std::async(std::launch::async,
      table_model::load_quiet_a_bunch_of_data,
      query, database, std::bind(loaded_callback, server_ptr, sessionId, inner_bind));
  Wt::WTimer::singleShot(20 * 1000, this, &amp;table_model::load_future_in_map);
  </code></pre>
  
  <p>Any suggestions?</p>