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 muCsutSetInterval and go the console.log("after");. 
Please suggest the right way to do it. Appreciate your help..
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,()=>{
    console.log("Callback");
});
console.log("after");
 
     
    