“JS dors” Réponses codées

JS dors

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 dors

// 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 dors

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

JS dors

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

JS dors

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

JS dors

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

Réponses similaires à “JS dors”

Questions similaires à “JS dors”

Plus de réponses similaires à “JS dors” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code