title: How to create your own setTimeout function?
body: <p>I understand how to use <code>setTimeout</code> function, but I can't find a way to create a function like it.<br>
  I have an example:</p>
  
  <pre><code>setTimeout(() =&gt; {
    console.log('3s');
  }, 3000);
  while(1);
  </code></pre>
  
  <p>The result is <code>setTimeout</code> callback never call so I think it use the same thread like every js other functions. But when it's check the time reach or not? and how it can do that?</p>
  
  <h2>Updated</h2>
  
  <p>To avoid misunderstanding I update my question.<br>
  I can't find a way to create a async function with callback after specify time (without using <code>setTimeout</code> and don't block entire thread). This function <code>setTimeout</code> seen like a miracle to me. I want to understand how it work.</p>