“Js Schlaf” Code-Antworten

Js Schlaf

function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}
console.log('First');
sleep(1000);
console.log('Second');
Code Cat

Js Schlaf

// sleep time expects milliseconds
function sleep (time) {
  return new Promise((resolve) => setTimeout(resolve, time));
}

// Usage!
sleep(500).then(() => {
    // Do something after the sleep!
});
Terrible Turtle

Js Schlaf

// Sync version
function sleep(sleepDuration){
    var now = new Date().getTime();
    while(new Date().getTime() < now + sleepDuration){ /* do nothing */ } 
}
Black Bird

Js Schlaf

function sleep(ms) {
    var start = new Date().getTime();
    while (new Date().getTime() < start + ms);
}
Clever Cheetah

Js Schlaf

/**
* Delay for a number of milliseconds
*/
function sleep(delay) {
    var start = new Date().getTime();
    while (new Date().getTime() < start + delay);
}
Roman Frolov

Js Schlaf

const sleep = require('util').promisify(setTimeout);
saggiyogesh

Ähnliche Antworten wie “Js Schlaf”

Fragen ähnlich wie “Js Schlaf”

Weitere verwandte Antworten zu “Js Schlaf” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen