title: How to set a time limit to run asynchronous function in node.js?
body: <p>There is a asynchronous function <code>fun(param, callback)</code> like this:</p>
  
  <pre><code>fun(param, function(err){
      if(err) console.log(err);
      doSomething();
  });
  </code></pre>
  
  <p>How do I set a time limit to run this function?<br>
  For example, I set time limit equals to 10 secs.<br>
  If it finish in 10 seconds, there is no error.<br>
  If it run exceed 10 seconds, terminate it and show error.</p>