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

fix: 🐛 #2581 修复 scheduler 任务调度的问题 (#2581) #2582

Merged
merged 2 commits into from
Aug 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/x6/src/util/scheduler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export namespace Scheduler {
const schedule = (cb: FlushTaskFn) => unit.push(cb) === 1 && postMessage()

const postMessage = (() => {
const cb = () => unit.splice(0, unit.length).forEach((c) => c())
const cb = () => unit.splice(0, unit.length)[0]?.()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接使用 unit.splice(0, 1).forEach((c) => c()) 比较好。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不清空 unit 队列的话会有 bug,会导致任务超时被挂起后,后续就再也不会被触发了(schedule 中由于 unit 没有被清空,所以永远满足不了 length 为 1 的条件,后续的 postMessage 也就不会被调用)

if (typeof MessageChannel !== 'undefined') {
const { port1, port2 } = new MessageChannel()
port1.onmessage = cb
Expand Down