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

zh-CN:Trans for 'Clarify when nextTickQueue is processed' #2026

Merged
1 commit merged into from Feb 3, 2019
Merged

zh-CN:Trans for 'Clarify when nextTickQueue is processed' #2026

1 commit merged into from Feb 3, 2019

Conversation

ghost
Copy link

@ghost ghost commented Feb 2, 2019

Ref:#1804

@nodejs/nodejs-cn

@@ -199,7 +199,7 @@ timeout

### 理解 `process.nextTick()`

您可能已经注意到 `process.nextTick()` 在关系图中没有显示,即使它是异步 API 的一部分。这是因为 `process.nextTick()` 在技术上不是事件循环的一部分。相反,无论事件循环的当前阶段如何,都将在当前操作完成后处理 `nextTickQueue`。
您可能已经注意到 `process.nextTick()` 在关系图中没有显示,即使它是异步 API 的一部分。这是因为 `process.nextTick()` 在技术上不是事件循环的一部分。相反,无论事件循环的当前阶段如何,都将在当前操作完成后处理 `nextTickQueue`。这里的一个*操作*被视作为一个从 C++ 底层处理开始过度,并且处理需要执行的 JavaScript 代码。

回顾我们的关系图,任何时候您调用 `process.nextTick()` 在给定的阶段中,所有传递到 `process.nextTick()` 的回调将在事件循环继续之前得到解决。这可能会造成一些糟糕的情况, 因为**它允许您通过进行递归 `process.nextTick()` 来“饿死”您的 I/O 调用**,阻止事件循环到达 **轮询** 阶段。
Copy link
Contributor

Choose a reason for hiding this comment

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

直译 饿死 不够生动形象。。。 递归更像撑死。

直接说 阻塞I/O 会不会好一些

Copy link
Author

@ghost ghost Feb 2, 2019

Choose a reason for hiding this comment

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

I/O调用因为异步轮询不断调用process.nextTick()始终得不到调用,所以始终处于“饥饿”状态,这是对的。而是说时间轮询队列被撑死了。
我们等一下其它人看法吧,我通读此文感觉这里的确是“饿死”,是说顺序执行的I/O始终得不到机会执行。

Copy link
Member

Choose a reason for hiding this comment

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

原文:

This can create some bad situations because it allows you to "starve" your I/O by making recursive process.nextTick() calls, which prevents the event loop from reaching the poll phase.

IMHO, 我是觉得没什么太大问题 :)

@ghost ghost requested a review from ZYSzys February 2, 2019 11:52
Copy link
Member

@ZYSzys ZYSzys left a comment

Choose a reason for hiding this comment

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

如果没理解错的话,event loop 应该翻译成 事件循环 吧。

Copy link
Member

@ZYSzys ZYSzys left a comment

Choose a reason for hiding this comment

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

LGTM

@ghost ghost merged commit c53bc56 into nodejs:master Feb 3, 2019
@ghost ghost deleted the nextTick branch February 3, 2019 02:38
ghost pushed a commit that referenced this pull request Feb 3, 2019
Because of the missing submission, we have to re-submit them together.

Ref 1: #2028,
Ref 2: #2026.
This pull request was closed.
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

Successfully merging this pull request may close these issues.

2 participants