“JS Schlaf 1 Sekunde” Code-Antworten

JavaScript Schlaf für 1 Sekunde

function delay(time) {
  return new Promise(resolve => setTimeout(resolve, time));
}

delay(1000).then(() => console.log('ran after 1 second1 passed'));
Powerful Puma

JavaScript -Schlaf

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...
}
Energetic Eagle

JavaScript -Schlaf

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!");
VahidTheGreat

JavaScript Schlaf 1 Sekunde

async function test() {
  console.log('start timer');
  await new Promise(resolve => setTimeout(resolve, 1000));
  console.log('after 1 second');
}

test();
Clear Cat

JS Schlaf 1 Sekunde

await new Promise(resolve => setTimeout(resolve, milliseconds))
xXjojaXx

JS Schlaf 1 Sekunde

setTimeout(myFunction, 3000);
Jonathan Diego Susanto

Ähnliche Antworten wie “JS Schlaf 1 Sekunde”

Fragen ähnlich wie “JS Schlaf 1 Sekunde”

Weitere verwandte Antworten zu “JS Schlaf 1 Sekunde” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen