code-for-vue-3-book icon indicating copy to clipboard operation
code-for-vue-3-book copied to clipboard

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

Open zhaoyunyes opened this issue 2 years ago • 1 comments

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

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

zhaoyunyes avatar Apr 07 '24 08:04 zhaoyunyes

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

zhaoyunyes avatar Apr 07 '24 08:04 zhaoyunyes