“Javascript Sleep 1 Second” Respostas de código

Javascript Sleep 1 Second

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

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

Javascript Sleep 1 Second

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

test();
Clear Cat

Javascript Sleep 1 Second

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

async function test() {
  console.log('start timer');
  await delay(1000);
  console.log('after 1 second');
}

test();
MorbidMeta

Javascript Sleep 1 Second

import time
def time_sleep ( sec=1.0 ):
  time.sleep( sec )
  return
Jirayu Kaewprateep

Javascript Sleep 1 Second

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

Javascript Sleep 1 Second

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

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

Javascript Sleep 1 Second

# this is just a trial of adding answers with Grepper
Mohieddine Farid

Javascript Sleep 1 Second

setTimeout(myFunction, 3000);

// if you have defined a function named myFunction 
// it will run after 3 seconds (3000 milliseconds)
function test1()
{    
    // let's say JavaScript did have a sleep function..
    // sleep for 3 seconds
    sleep(3000);

    alert('hi'); 
}
Kalyani Sree Selvaganesan

Javascript Sleep 1 Second

// `sleep' function from @Clever Cheetah
function sleep(delay) {
    let start = new Date().getTime();
    while (new Date().getTime() < start + delay);
}

sleep(1000);
console.log("Do something")
Tame Tern

Javascript Sleep 1 Second

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

delay(1000).then(() => console.log('ran after 1 second passed'));
Davin Leo

Respostas semelhantes a “Javascript Sleep 1 Second”

Perguntas semelhantes a “Javascript Sleep 1 Second”

Procure respostas de código populares por idioma

Procurar outros idiomas de código