Answers for "javascript delay"

29

javascript sleep

const sleep = (milliseconds) => {
  return new Promise(resolve => setTimeout(resolve, milliseconds))
}

/*Use like so*/

async function timeSensativeAction(){ //must be async func
  //do something here
  await sleep(5000) //wait 5 seconds
  //continue on...
}
Posted by: Guest on December-13-2019
18

javascript set delay

var delayInMilliseconds = 1000; //1 second

setTimeout(function() {
  //your code to be executed after 1 second
}, delayInMilliseconds);
Posted by: Guest on January-31-2020
3

javascript wait 1 second

setTimeout(function(){ 
    console.log("Ready")
}, 1000);
Posted by: Guest on November-11-2020
4

delay in javascript

setTimeout(function() {
 //your code here
}, 1000);
Posted by: Guest on November-03-2020
6

javascript sleep

function sleep(milliseconds) {
  const date = Date.now();
  let currentDate = null;
  do {
    currentDate = Date.now();
  } while (currentDate - date < milliseconds);
}

console.log("Hello");
sleep(2000);
console.log("World!");
Posted by: Guest on December-09-2020
1

javascript delay

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

console.log("Hello");
sleep(2000).then(() => { console.log("World!"); });
Posted by: Guest on May-16-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language