Answers for "javascript thread sleep"

1

node wait 10 seconds

async function init() {
  console.log(1);
  await sleep(1000);
  console.log(2);
}

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

// one liner
let sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
Posted by: Guest on March-30-2020
5

sleep javascript

//Javascipt is asyncronous so you can't pause/block code execution
//You can delay doing something with setTimeout
setTimeout(function(){
 	alert("Sup!"); 
}, 2000);//wait 2 seconds
Posted by: Guest on July-23-2019
1

javascript sleep settimeout

setTimeout(() => {  console.log("World!"); }, 2000);
Posted by: Guest on March-13-2020
0

javascript sleep thread

var millisecondsToWait = 500;
setTimeout(function() {
    // Whatever you want to do after the wait
}, millisecondsToWait);
Posted by: Guest on September-08-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language