Answers for "js 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
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