title: How do I make my function as asynchronous in Javascript?
body: <p>I am trying to understand the async behaviour of Javascript, how can we implement in normal functions. For example below code I am trying to implement a custom SetTimeout function which would work asynchronously. It should call the function <code>muCsutSetInterval</code> and go the <code>console.log("after");</code>. </p>
  
  <p>Please suggest the right way to do it. Appreciate your help..</p>
  
  <pre><code>var myCustSetInterval = function (time, callback){
      let initial = new Date();
      let current;
      while(true){
          current = new Date();
          if(current.getTime()-initial.getTime()===time){
              break;
          }
      }
      callback();
  }
  
  console.log("before");
  
  myCustSetInterval(5000,()=&gt;{
      console.log("Callback");
  });
  
  console.log("after");
  </code></pre>