You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: locale/ko/docs/guides/event-loop-timers-and-nexttick.md
+67-60Lines changed: 67 additions & 60 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,24 +43,24 @@ The following diagram shows a simplified overview of the event loop's
43
43
order of operations.
44
44
45
45
```
46
-
┌───────────────────────┐
47
-
┌─>│ timers │
48
-
│ └──────────┬────────────┘
49
-
│ ┌──────────┴────────────┐
50
-
│ │ pending callbacks │
51
-
│ └──────────┬────────────┘
52
-
│ ┌──────────┴────────────┐
53
-
│ │ idle, prepare │
54
-
│ └──────────┬────────────┘ ┌───────────────┐
55
-
│ ┌──────────┴────────────┐ │ incoming: │
56
-
│ │ poll │<─────┤ connections, │
57
-
│ └──────────┬────────────┘ │ data, etc. │
58
-
│ ┌──────────┴────────────┐ └───────────────┘
59
-
│ │ check │
60
-
│ └──────────┬────────────┘
61
-
│ ┌──────────┴────────────┐
62
-
└──┤ close callbacks │
63
-
└───────────────────────┘
46
+
┌───────────────────────────┐
47
+
┌─>│ timers │
48
+
│ └─────────────┬─────────────┘
49
+
│ ┌─────────────┴─────────────┐
50
+
│ │ pending callbacks │
51
+
│ └─────────────┬─────────────┘
52
+
│ ┌─────────────┴─────────────┐
53
+
│ │ idle, prepare │
54
+
│ └─────────────┬─────────────┘ ┌───────────────┐
55
+
│ ┌─────────────┴─────────────┐ │ incoming: │
56
+
│ │ poll │<─────┤ connections, │
57
+
│ └─────────────┬─────────────┘ │ data, etc. │
58
+
│ ┌─────────────┴─────────────┐ └───────────────┘
59
+
│ │ check │
60
+
│ └─────────────┬─────────────┘
61
+
│ ┌─────────────┴─────────────┐
62
+
└──┤ close callbacks │
63
+
└───────────────────────────┘
64
64
```
65
65
66
66
*note: each box will be referred to as a "phase" of the event loop.*
@@ -76,24 +76,24 @@ Node.js를 시작할 때 이벤트 루프를 초기화하고 제공된 입력
76
76
아래 다이어그램은 이벤트 루프의 작업 순서의 간단한 개요를 보여줍니다.
77
77
78
78
```
79
-
┌───────────────────────┐
80
-
┌─>│ timers │
81
-
│ └──────────┬────────────┘
82
-
│ ┌──────────┴────────────┐
83
-
│ │ pending callbacks │
84
-
│ └──────────┬────────────┘
85
-
│ ┌──────────┴────────────┐
86
-
│ │ idle, prepare │
87
-
│ └──────────┬────────────┘ ┌───────────────┐
88
-
│ ┌──────────┴────────────┐ │ incoming: │
89
-
│ │ poll │<─────┤ connections, │
90
-
│ └──────────┬────────────┘ │ data, etc. │
91
-
│ ┌──────────┴────────────┐ └───────────────┘
92
-
│ │ check │
93
-
│ └──────────┬────────────┘
94
-
│ ┌──────────┴────────────┐
95
-
└──┤ close callbacks │
96
-
└───────────────────────┘
79
+
┌───────────────────────────┐
80
+
┌─>│ timers │
81
+
│ └─────────────┬─────────────┘
82
+
│ ┌─────────────┴─────────────┐
83
+
│ │ pending callbacks │
84
+
│ └─────────────┬─────────────┘
85
+
│ ┌─────────────┴─────────────┐
86
+
│ │ idle, prepare │
87
+
│ └─────────────┬─────────────┘ ┌───────────────┐
88
+
│ ┌─────────────┴─────────────┐ │ incoming: │
89
+
│ │ poll │<─────┤ connections, │
90
+
│ └─────────────┬─────────────┘ │ data, etc. │
91
+
│ ┌─────────────┴─────────────┐ └───────────────┘
92
+
│ │ check │
93
+
│ └─────────────┬─────────────┘
94
+
│ ┌─────────────┴─────────────┐
95
+
└──┤ close callbacks │
96
+
└───────────────────────────┘
97
97
```
98
98
99
99
*note: 각 박스는 이벤트 루프의 "단계"를 의미합니다.*
@@ -142,9 +142,12 @@ _**NOTE:** 윈도우와 Unix/Linux 구현체간에 약간의 차이가 있지만
142
142
143
143
* **timers**: this phase executes callbacks scheduled by `setTimeout()`
144
144
and `setInterval()`.
145
-
* **pending callbacks**: executes I/O callbacks deferred to the next loop iteration.
145
+
* **pending callbacks**: executes I/O callbacks deferred to the next loop
146
+
iteration.
146
147
* **idle, prepare**: only used internally.
147
-
* **poll**: retrieve new I/O events; execute I/O related callbacks (almost all with the exception of close callbacks, the ones scheduled by timers, and `setImmediate()`); node will block here when appropriate.
148
+
* **poll**: retrieve new I/O events; execute I/O related callbacks (almost
149
+
all with the exception of close callbacks, the ones scheduled by timers,
150
+
and `setImmediate()`); node will block here when appropriate.
148
151
* **check**: `setImmediate()` callbacks are invoked here.
149
152
* **close callbacks**: some close callbacks, e.g. `socket.on('close', ...)`.
150
153
@@ -309,7 +312,7 @@ error. This will be queued to execute in the **pending callbacks** phase.
309
312
310
313
The **poll** phase has two main functions:
311
314
312
-
1. Executing scripts for timers whose threshold has elapsed, then
315
+
1. Calculating how long it should block and poll for I/O, then
313
316
2. Processing events in the **poll** queue.
314
317
315
318
When the event loop enters the **poll** phase _and there are no timers
@@ -325,7 +328,7 @@ is reached.
325
328
326
329
**poll** 단계는 두 가지 주요 기능을 가집니다.
327
330
328
-
1.임계 값이 지난 타이머의 스크립트를 실행합니다. 그다음
331
+
1.I/O를 얼마나 오래 블록하고 폴링해야 하는지 계산합니다. 그 다음
329
332
2.**poll** 큐에 있는 이벤트를 처리합니다.
330
333
331
334
이벤트 루프가 **poll** 단계에 진입하고 _스케줄링된 타이머가 없을 때_
@@ -413,11 +416,11 @@ emitted via `process.nextTick()`.
413
416
<!--
414
417
## `setImmediate()` vs `setTimeout()`
415
418
416
-
`setImmediate` and `setTimeout()` are similar, but behave in different
419
+
`setImmediate()` and `setTimeout()` are similar, but behave in different
417
420
ways depending on when they are called.
418
421
419
-
* `setImmediate()` is designed to execute a script once the current
420
-
**poll** phase completes.
422
+
* `setImmediate()` is designed to execute a script once the
423
+
current **poll** phase completes.
421
424
* `setTimeout()` schedules a script to be run after a minimum threshold
422
425
in ms has elapsed.
423
426
@@ -560,8 +563,11 @@ timeout
560
563
You may have noticed that `process.nextTick()` was not displayed in the
561
564
diagram, even though it's a part of the asynchronous API. This is because
562
565
`process.nextTick()` is not technically part of the event loop. Instead,
563
-
the `nextTickQueue` will be processed after the current operation
564
-
completes, regardless of the current phase of the event loop.
566
+
the `nextTickQueue` will be processed after the current operation is
567
+
completed, regardless of the current phase of the event loop. Here,
568
+
an *operation* is defined as a transition from the
569
+
underlying C/C++ handler, and handling the JavaScript that needs to be
570
+
executed.
565
571
566
572
Looking back at our diagram, any time you call `process.nextTick()` in a
567
573
given phase, all callbacks passed to `process.nextTick()` will be
@@ -577,8 +583,9 @@ from reaching the **poll** phase.
577
583
578
584
`process.nextTick()`이 비동기 API에 속해있지만, 다이어그램에는 표시되지 않은 것을
579
585
눈치챘을 겁니다. 이는 `process.nextTick()`이 기술적으로는 이벤트 루프의 일부가
580
-
아니기 때문입니다. 대신 `process.nextTick()`은 이벤트 루프의 현재 단계와 관계없이
581
-
현재 작업이 완료된 후에 처리될 것입니다.
586
+
아니기 때문입니다. 대신 `nextTickQueue`는 이벤트 루프의 현재 단계와 관계없이
587
+
현재 작업이 완료된 후에 처리될 것입니다. 여기에서 *작업*이란 기저의 C/C++
588
+
핸들러에서 전환하는 것, 또 실행되어야 하는 JavaScript를 처리하는 것을 말합니다.
582
589
583
590
다이어그램을 다시 보겠습니다. 해당 단계에서 `process.nextTick()`을 호출하면
584
591
`process.nextTick()`에 전달한 모든 콜백은 언제나 이벤트 루프를 계속 진행하기
@@ -730,12 +737,12 @@ const server = net.createServer(() => {}).listen(8080);
730
737
server.on('listening', () => {});
731
738
```
732
739
733
-
When only a port is passed the port is bound immediately. So the
734
-
`'listening'` callback could be called immediately. Problem is that the
735
-
`.on('listening')` will not have been set by that time.
740
+
When only a port is passed, the port is bound immediately. So, the
741
+
`'listening'` callback could be called immediately. The problem is that the
742
+
`.on('listening')` callback will not have been set by that time.
736
743
737
-
To get around this the `'listening'` event is queued in a `nextTick()`
738
-
to allow the script to run to completion. Which allows the user to set
744
+
To get around this, the `'listening'` event is queued in a `nextTick()`
745
+
to allow the script to run to completion. This allows the user to set
0 commit comments