Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
wjgogogo committed Dec 30, 2024
1 parent 169f094 commit 2d2d095
Show file tree
Hide file tree
Showing 8 changed files with 1,001 additions and 1 deletion.
415 changes: 415 additions & 0 deletions packages/rspress-site/docs/guide/scheduler.mdx

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions packages/rspress-site/docs/public/d2/mini-scheduler-v1.d2
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
direction: right

taskQueue: {
grid-columns: 3
task1
task2
task3
}

schedule -> taskQueue

perform: {
hasTask: 还存在任务 {
shape: diamond
}

peek: peek\n取出优先级最高的任务

hasTask -> peek: yes
peek -> execute -> hasTask
}

taskQueue -> perform.hasTask
perform.hasTask -> end: no
128 changes: 128 additions & 0 deletions packages/rspress-site/docs/public/d2/mini-scheduler-v1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions packages/rspress-site/docs/public/d2/mini-scheduler-v2.d2
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
direction: right

taskQueue: {
grid-columns: 3
task1
task2
task3
}

schedule -> taskQueue

schedulePerform: schedulePerform\n(通过宏任务延迟调用 perform)

perform: {
hasTask: 还存在任务 {
shape: diamond
}

peek: peek\n取出优先级最高的任务

hasTask -> peek: yes
peek -> execute -> hasTask
}

taskQueue -> schedulePerform -> perform.hasTask
perform.hasTask -> end: no
129 changes: 129 additions & 0 deletions packages/rspress-site/docs/public/d2/mini-scheduler-v2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
117 changes: 117 additions & 0 deletions packages/rspress-site/docs/public/d2/scheduler.d2
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
direction: down
*.style: {
border-radius: 8
}
Queue: {
TimerQueue: TimerQueue(延迟任务队列)\n优先级按照 startTime 排序 {
timer1 -> timer2 -> timer3
}

TaskQueue: TaskQueue(立即执行任务队列)\n优先级按照 expirationTime 排序 {
task1 -> task2 -> task3
}

shouldDelay: 是否是延迟任务 {
shape: diamond
}
shouldDelay -> TimerQueue: yes

shouldDelay -> TaskQueue: no
}

Schedule: {
isFirstTimer: 当前任务是优先级最高的延迟任务\n且不存在立即执行的任务 {
shape: diamond
width: 360
}

requestHostTimeout: requestHostTimeout\n(使用 timeout 延迟,之后再次检查任务情况)

handleTimeout: {
style: {
stroke-dash: 6
}
advanceTimers: advanceTimers\n(将所有到期的延迟任务移动到TaskQueue中)

hasDelayTask: TaskQueue存在任务 {
shape: diamond
}

advanceTimers -> hasDelayTask
}

schedulePerformWorkUntilDeadline: schedulePerformWorkUntilDeadline\n(通过宏任务延迟调用 performWorkUntilDeadline)

handleTimeout.hasDelayTask -> requestHostTimeout: no

handleTimeout.hasDelayTask -> requestHostCallback: yes

isFirstTimer -> requestHostTimeout: yes

requestHostTimeout -> handleTimeout

requestHostCallback -> schedulePerformWorkUntilDeadline
}

Execution: {
performWorkUntilDeadline -> flushWork -> workLoop.advanceTimers

workLoop: {
style: {
stroke-dash: 6
}
advanceTimers: advanceTimers\n(将所有到期的延迟任务移动到TaskQueue中)

peek: peek\n(从 TaskQueue 中选择优先级最高的任务)

shouldYield: 立即执行任务已经到期\n并且不需要让出主线程给浏览器 {
shape: diamond
width: 400
}

execute: 执行任务

finish: 当前任务执行完成 {
shape: diamond
width: 200
}

advanceTimers -> peek -> shouldYield

shouldYield -> execute: yes

execute -> finish

finish -> advanceTimers: yes
}

hasMore: 存在其他立即执行任务 {
shape: diamond
width: 300
}

hasMoreDelay: 存在其他延迟任务 {
shape: diamond
width: 300
}

workLoop.shouldYield -> hasMore: no

hasMore -> hasMoreDelay: no
}

push: push\n(根据优先级生成任务)

scheduleCallback -> push -> Queue.shouldDelay

Queue.TimerQueue -> Schedule.isFirstTimer

Queue.TaskQueue -> Schedule.requestHostCallback

Schedule.schedulePerformWorkUntilDeadline -> Execution.performWorkUntilDeadline

Execution.workLoop.finish -> Schedule.schedulePerformWorkUntilDeadline: no
Execution.hasMore -> Schedule.schedulePerformWorkUntilDeadline: yes

Execution.hasMoreDelay -> Schedule.requestHostTimeout: yes
Execution.hasMoreDelay -> end: no
161 changes: 161 additions & 0 deletions packages/rspress-site/docs/public/d2/scheduler.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/rspress-site/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
content: ["./components/**/*.tsx", "./docs/**/*.mdx"],
content: ["./src/**/*.tsx", "./docs/**/*.mdx"],
theme: {
extend: {},
},
Expand Down

0 comments on commit 2d2d095

Please sign in to comment.