title: c++ futures/promises like javascript?
body: <p>I've been writing some javascript and one of the few things I like about the environment is the way it uses promises/futures to make handlers for asynchronous events.</p>
  
  <p>In C++ you have to call .get on a future and it blocks until the result of the future is available but in Javascript you can write .then(fn) and it will call the function when the result is ready. Critically it does this in the same thread as the caller at a later time so there are no thread synchronization issues to worry about, at least not the same ones as in c++.</p>
  
  <p>I'm thinking in c++ something like -</p>
  
  <pre><code>auto fut = asyncImageLoader("cat.jpg");
  fut.then([](Image img) { std::cout &lt;&lt; "Image is now loaded\n" &lt;&lt; image; });
  </code></pre>
  
  <p>Is there any way to achieve this in c++? Clearly it will need some kind of event queue and event loop to handle dispatching the callbacks. I could probably eventually write the code to do most of this but wanted to see if there was any way to achieve the goal easily using standard facilities.</p>