Answers for "nodejs delay"

10

node sleep

// one liner
await new Promise(resolve => setTimeout(resolve, 5000));

// or re-usable `sleep` function:
async function init() {
  console.log(1);
  await sleep(1000);
  console.log(2);
}

function sleep(ms) {
  return new Promise((resolve) => {
    setTimeout(resolve, ms);
  });
}
Posted by: Guest on March-31-2020
2

sleep in nodejs?

await sleep(1000)
function sleep(ms) {
  return new Promise((resolve) => {
    setTimeout(resolve, ms);
  });
}
Posted by: Guest on July-18-2020
1

javascipt 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
1

javascipt delay

async function delay(delayInms) {
      return new Promise(resolve  => {
        setTimeout(() => {
          resolve(2);
        }, delayInms);
      });
    }
    async function sample() {
      console.log('a');
      console.log('waiting...')
      let delayres = await delay(3000);
      console.log('b');
    }
    sample();
Posted by: Guest on May-16-2020
-1

node scripts delay

"scripts": {  "test:system": "npm-run-all build -p -r serve test",  "build": "webpack",  "serve": "serve -p 8000",  "test": "wait-on http://localhost:8001 && npm run test:codecept",  "test:codecept": "codecept",}
Posted by: Guest on July-21-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language