Skip to content

Commit

Permalink
docs: update issue 348
Browse files Browse the repository at this point in the history
  • Loading branch information
toFrankie committed Aug 17, 2024
1 parent 33927ec commit efe99cb
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions archives/2024/348.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: 通过两个例子再探 Event Loop
number: '#348'
link: 'https://github.com/toFrankie/blog/issues/348'
created_at: '2024-08-11 16:42:16'
updated_at: '2024-08-17 23:51:15'
updated_at: '2024-08-17 23:55:14'
labels:
- 前端
- JS
Expand Down Expand Up @@ -52,7 +52,7 @@ while (true) {
}
```

没错,它是一个无限循环的。它 7 × 24 随时待命,只要任务队列有任务,它就不断地从队列中取出一个任务执行完,接着下一个,直到执行完队列中所有任务。
没错,它是无限循环的,7 × 24 随时待命,只要任务队列有任务,它就不断地从队列中取出一个任务执行完,接着下一个,直到执行完队列中所有任务。

### 什么是任务?

Expand Down Expand Up @@ -97,5 +97,14 @@ while (true) {

> 比如 React 16 的调度机制,可以控制中断当前执行中的任务,执行完优先级更高的任务(比如更新 DOM),完了再继续此前未完成的任务,以解决某些场景下页面卡顿的问题。
所以,Event Loop 变成了这样:

```js
while (true) {
task = taskQueue.pop()
execute(task)

if (isRepaintTime()) repaint()
}

```

0 comments on commit efe99cb

Please sign in to comment.