I have two setTimeOut here. The second setTimeOut must be called after the first time out.
setTimeout(() => {
mack.classList.add('loaded');
}, 3000);
setTimeout(() => {
location.reload(true);
}, 4000);
But I know that this is not a good solution on this. So I tried to do a Promise:
const timer = ms => new Promise(res => setTimeout(res, ms));
Promise.all([
timer(3000).then(mack.classList.add('loaded')),
timer(1000).then(location.reload(true))
])
This however, did not work. How can I fix this to make it call in order? Also, is there a version to do this using asynchronous?
thenof the first timer? Also, pass a function to thethenlike you do withsetTimeout. At the moment it won't workawait timer(3000) await timer(1000)how to I add the code then like the adding of classlist?(async () => { await timer(3000); mack.classList.add('loaded'); await timer(1000); location.reload(true); })();