title: C++ - Modern way to implement JS's setTimeout
body: <p>I am building an app where requests come in on a <code>zeromq</code> socket. For each request I want to do some processing and send a response, however if a predefined time elapses I want to send the response immediately. </p>
  
  <p>In node.js, I would do something like:</p>
  
  <pre><code>async function onRequest(req, sendResponse) {
    let done = false;
  
    setTimeout(() =&gt; {
      if (!done) {
        done = true;
        sendResponse('TIMED_OUT');
      }
    }, 10000);
  
    await doSomeWork(req); // do some async work
    if (!done) {
      done = true;
      sendResponse('Work done');
    }
  }
  </code></pre>
  
  <p>Only thing I'm stuck on right now, is setting in the timeout in c++. Don't have a lot of experience with c++, but I am aware there are things in c++11 that would let me do this cleanly.</p>
  
  <p>How should I go about this?</p>