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

【2021-07-27】如何实现 sleep 的效果 #16

Open
superDCH opened this issue Jul 27, 2021 · 2 comments
Open

【2021-07-27】如何实现 sleep 的效果 #16

superDCH opened this issue Jul 27, 2021 · 2 comments

Comments

@superDCH
Copy link
Owner

No description provided.

@superDCH
Copy link
Owner Author

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

调用:

sleep(5000).then(()=>{
    console.log('aaa')
})

@superDCH
Copy link
Owner Author

function sleep(ms, fn) {
  let start = Date.now();
  expire = start + ms;
  while (Date.now() < expire);
  fn();
  return;
}

调用:

sleep(5000,()=>{console.log('aaa')})

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

No branches or pull requests

1 participant