<script>
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
function customFunc(argument)
{
sleep(1000);
console.log("Inside third party custom function for event = " + argument.event);
}
var aO = {
tt:{
cf : customFunc
}};
</script>
I have written a custom sleep function in Javascript which would sleep for the milliseconds it takes as an argumentin sleep function and I have called it in customFunc in which I want to create a delay.Is this the right way or is there any other way I can do it better.
setTimeout. Busy waiting isn't a good idea.