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

flushJob方法为什么不在finally里面调用jobQueue.clear()清空队列? #218

Open
zhaoyunyes opened this issue Apr 7, 2024 · 1 comment

Comments

@zhaoyunyes
Copy link

zhaoyunyes commented Apr 7, 2024

/** 刷新(执行)任务队列 */
function flushJob() {
  if (isFlushing) return;
  isFlushing = true;
  p.then(() => {
    jobQueue.forEach((job: any) => job());
  }).finally(() => {
    isFlushing = false;
    // 清空队列
    jobQueue.clear();
  });
}

如果不清空,看起来会在下一个任务周期中数据变化后不需要执行的job再次执行(某些条件下,job应该被cleanup并且不需要再执行了)

@zhaoyunyes
Copy link
Author

ps:看的是电子书不知道第几页
不过代码在4.7篇章

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

1 participant