I expect page loading to be finished at second 2
and at second 4
, in console.log we should see another text. but the code is synchronous, not asynchronous. so page loading will finish after 4 seconds.
const sleep = (millisecond = 1000) => {
return new Promise((resolve, reject) => {
const date = Date.now();
while (Date.now() - date < millisecond) {}
console.log(millisecond + ' sleep finished ' + Date.now());
});
};
sleep(2000).then();
async function asyncFunc() {
sleep(2000);
};
asyncFunc().then();