“JS dors 1 seconde” Réponses codées

JavaScript dors pendant 1 seconde

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

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

sommeil javascript

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

sommeil javascript

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 Sleep 1 seconde

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

test();
Clear Cat

JS dors 1 seconde

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

JS dors 1 seconde

setTimeout(myFunction, 3000);
Jonathan Diego Susanto

Réponses similaires à “JS dors 1 seconde”

Questions similaires à “JS dors 1 seconde”

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

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code