Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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);
  });
}
Comment

sleep in nodejs?

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

node sleep

await sleep(1000)
const sleep = (ms: number) => {
  return new Promise((resolve) => {
    setTimeout(resolve, ms);
  });
} 
Comment

PREVIOUS NEXT
Code Example
Javascript :: js loop ul 
Javascript :: how to get all elements with same class in javascript 
Javascript :: joi.validate is not a function 
Javascript :: javascript detect dark mode 
Javascript :: settimeout es6 
Javascript :: js stop form submit 
Javascript :: chart js title 
Javascript :: random index js 
Javascript :: write file with deno 
Javascript :: object key value as string ts type js 
Javascript :: js startswith 
Javascript :: datatable default sorting 
Javascript :: javascript detect mobile device 
Javascript :: how to check wether the property exist in a object in java script 
Javascript :: react-redux imports 
Javascript :: hide show div using jquery 
Javascript :: javascript fill 2d array 
Javascript :: delegate click in jquery 
Javascript :: fullscreen electron 
Javascript :: select2 get selected value 
Javascript :: error java.io.filenotfoundexception tessdata/eng.traineddata 
Javascript :: jquery scroll into view 
Javascript :: jquery insert element as first child 
Javascript :: jquery onclick not working 
Javascript :: NullInjectorError: R3InjectorError httpclient 
Javascript :: jquery get checked checkbox values array 
Javascript :: TypeError: Promise resolver undefined is not a function 
Javascript :: javascript format number as currency 
Javascript :: remove first 3 characters from string javascript 
Javascript :: get select option count using jquery 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =