I want to pause else part for 3 seconds in JavaScript. How I can?
async function fun1() {
try {
if(condition) {
//your statements
} else {
await sleep(3000);
//now execute your else code
}
} catch(err) {
console.log('Error is: ', err);
}
}
function sleep(duration) {
return new Promise((resolve, reject)=> {
setTimeout(()=> resolve('time complete'), duration);
})
}
var check = function() { if(condition) { // run when condition is met } else { await sleep(1000);// check again in a second } }