Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 Promise 实现每隔三秒输出时间 #145

Open
Sunny-117 opened this issue Nov 3, 2022 · 3 comments
Open

使用 Promise 实现每隔三秒输出时间 #145

Sunny-117 opened this issue Nov 3, 2022 · 3 comments

Comments

@Sunny-117
Copy link
Owner

No description provided.

@mengqiuleo
Copy link

const task = (timer) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      console.log(new Date())
      resolve()
    }, timer);
  })
}

const taskRunner = async () => {
  await task(3000);
  taskRunner();
}
taskRunner();

@bearki99
Copy link

function showTime(){
    return new Promise((resolve, reject)=>{
        setTimeout(()=>{
            console.log(new Date());
            resolve();
        }, 3000);
    })
}
const time = async () => {
    await showTime();
    time();
}
time();

@cscty
Copy link

cscty commented Jun 19, 2023

const task = (timer) => {
    return new Promise((resovle) =>
        setTimeout(() => {
            console.log(1);
            resovle();
            task(timer);
        }, timer)
    );
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants