-
Notifications
You must be signed in to change notification settings - Fork 6.5k
JA : Translate middle of "setImmediate" #2356
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
Merged
+204
−1
Merged
Changes from 78 commits
Commits
Show all changes
82 commits
Select commit
Hold shift + click to select a range
7781f63
translate to japanese index.md of Get involved.
silverskyvicto 17fd5cf
translate to japanese contribute.md.
silverskyvicto 8e9fe26
translate to japanese code-and-learn.md.
silverskyvicto c2f14c2
translate to japanese node-events.md.
silverskyvicto 78b96fe
ranslate to japanese collab-summit.md.
silverskyvicto d014002
translate to japanese node-meetups.md.
silverskyvicto 1e87896
translate to japanese node-speakers.md.
silverskyvicto 716c8d6
translate title
silverskyvicto df0e63b
translate dependencies.md in Japanese.
silverskyvicto 08853a6
List translation is unnecessary.
silverskyvicto 2deeb95
Translation is unnecessary except for title.
silverskyvicto f746e2e
translate japanese.
silverskyvicto 3b6d45a
fix japanese translation.
silverskyvicto 72d8a18
fixed translation style.
silverskyvicto b16c9b1
fixed dependencies.md translation style.
silverskyvicto a368812
fixed debugging-getting-started translation style.
silverskyvicto 774bd16
Update locale/ja/get-involved/collab-summit.md
silverskyvicto 7fc2402
Update locale/ja/get-involved/code-and-learn.md
silverskyvicto 0df90e4
Update locale/ja/get-involved/collab-summit.md
silverskyvicto 616df0d
fixed simple-profiling.md translation style.
silverskyvicto eac7cab
translate a part of diagnostics-flamegraph.md
silverskyvicto c5b269e
fixed a part of collab-summit translation.
silverskyvicto c149d1a
Merge branch 'translate/ja' of github.com:silverskyvicto/nodejs.org i…
silverskyvicto 6eeb46d
Update locale/ja/docs/guides/debugging-getting-started.md
silverskyvicto 35aa9ff
fixed review point.
silverskyvicto e125017
fixed review point.
silverskyvicto a3f1e9e
Update locale/ja/docs/guides/diagnostics-flamegraph.md
silverskyvicto f4c68fe
Merge branch 'translate/guide' of github.com:silverskyvicto/nodejs.or…
silverskyvicto 35920ab
fixed review point.
silverskyvicto 75f64cf
translate before "Why do I need them at all?"
silverskyvicto 62a1ac6
Merge branch 'master' of https://github.com/silverskyvicto/nodejs.org…
rsebihara 23aed62
Merge branch 'master' of https://github.com/silverskyvicto/nodejs.org…
rsebihara 5e6cd2f
Merge branch 'translate/guide'
rsebihara dd0bc4e
translate japanese.
silverskyvicto 9759b07
Merge branch 'translate/guide' of github.com:silverskyvicto/nodejs.or…
silverskyvicto 8a54033
translate into japanese.
silverskyvicto 0814347
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto 84851ed
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto d9d0b25
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto 668698f
Merge branch 'master' of github.com:silverskyvicto/nodejs.org
silverskyvicto 60d3aef
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto d4757c2
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto 84fc9c1
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto baf3e5f
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto 6a2cf83
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto 4357f22
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto c69b852
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto 7396b82
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto f6956ba
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto acfa793
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto 868e43e
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto 5f0a972
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto 33c8e9a
translate before Phase2
silverskyvicto 8391208
translate first polyfill
silverskyvicto 600d062
Merge branch 'translate/guide' of github.com:silverskyvicto/nodejs.or…
silverskyvicto 77225bd
Merge remote-tracking branch 'upstream/master'
silverskyvicto f2d9018
fixed review point
silverskyvicto 13daa31
Merge branch 'translate/guide'
rsebihara e408a36
Merge branch 'master' of https://github.com/nodejs/nodejs.org
rsebihara 3420875
Merge remote-tracking branch 'upstream/master'
silverskyvicto b658878
Merge branch 'master' of github.com:silverskyvicto/nodejs.org
silverskyvicto 9bd9806
Merge remote-tracking branch 'upstream/master' into translate/guide
silverskyvicto f63805e
translate one list item.
silverskyvicto 5504f68
Merge branch 'master' of https://github.com/nodejs/nodejs.org
rsebihara 8c17d75
Merge remote-tracking branch 'upstream/master'
silverskyvicto 90c1af2
Merge branch 'master' of github.com:silverskyvicto/nodejs.org
silverskyvicto 2efad39
translate one list item.
silverskyvicto 6bd0d63
Merge branch 'translate/guide' of github.com:silverskyvicto/nodejs.or…
silverskyvicto 56fa9e1
translate before variant 3.
silverskyvicto 399cf21
translate before Regarding `Buffer.allocUnsafe()`
silverskyvicto 646c881
translate before faq.
silverskyvicto a2e2b56
translate to last.
silverskyvicto 35c7588
translate blocking-vs-non-blocking into japanese.
silverskyvicto 7acb7e9
Merge remote-tracking branch 'upstream/master'
silverskyvicto 0164819
Merge remote-tracking branch 'upstream/master'
silverskyvicto e71b8b1
Translate middle of "setImmediate" into japanese.
silverskyvicto 72b428a
Translate middle of "setImmediate" into japanese.
silverskyvicto 8b70388
Merge branch 'translate/guide' of github.com:silverskyvicto/nodejs.or…
silverskyvicto da07eba
Fixed Review Point.
silverskyvicto 47eceb1
Translate before "Leaving Timeouts Behind"
silverskyvicto a87a07e
Translate remained part.
silverskyvicto d98a95b
Fixed conjunction.
silverskyvicto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| --- | ||
| title: Timers in Node.js | ||
| title: Node.js のタイマー | ||
| layout: docs.hbs | ||
| --- | ||
|
|
||
| <!-- | ||
| # Timers in Node.js and beyond | ||
|
|
||
| The Timers module in Node.js contains functions that execute code after a set | ||
|
|
@@ -12,6 +13,17 @@ To fully understand when timer functions will be executed, it's a good idea to | |
| read up on the the Node.js | ||
| [Event Loop](/en/docs/guides/event-loop-timers-and-nexttick/). | ||
|
|
||
| --> | ||
| # Node.js のタイマーと仕組み | ||
|
|
||
| Node.js の Timers モジュールには、 | ||
| 一定期間後にコードを実行する関数が含まれています。 | ||
| ブラウザの JavaScript API をエミュレートするためにすべてのメソッドがグローバルに利用可能であるため、 | ||
| `require()` を介してタイマーをインポートする必要はありません。 | ||
| タイマー関数がいつ実行されるかを完全に理解するためには、 | ||
| Node.js の[イベントループ](/ja/docs/guides/event-loop-timers-and-nexttick/)を読むことをお勧めします。 | ||
|
|
||
| <!-- | ||
| ## Controlling the Time Continuum with Node.js | ||
|
|
||
| The Node.js API provides several ways of scheduling code to execute at | ||
|
|
@@ -21,6 +33,17 @@ its own implementation of these methods. Timers integrate very closely | |
| with the system, and despite the fact that the API mirrors the browser | ||
| API, there are some differences in implementation. | ||
|
|
||
| --> | ||
| ## Node.js を使って連続した時間を制御する | ||
|
|
||
| Node.js APIには、現時点以降のある時点でコードを実行するように | ||
| スケジューリングする方法がいくつかあります。 | ||
| 以下の関数はほとんどのブラウザで利用可能であるためおなじみのように思われるかもしれませんが、 | ||
| Node.js は実際にはこれらのメソッドの独自の実装を提供します。 | ||
| タイマーはシステムと非常に密接に統合されており、 | ||
| API がブラウザ API を反映しているという事実があるにもかかわらず、実装にはいくつかの違いがあります。 | ||
|
|
||
| <!-- | ||
| ### "When I say so" Execution ~ *`setTimeout()`* | ||
|
|
||
| `setTimeout()` can be used to schedule code execution after a designated | ||
|
|
@@ -56,6 +79,43 @@ timeout that was set. This returned object can be used to cancel the timeout ( | |
| see `clearTimeout()` below) as well as change the execution behavior (see | ||
| `unref()` below). | ||
|
|
||
| --> | ||
| ### "そう言うとき" 実行する ~ *`setTimeout()`* | ||
|
|
||
| `setTimeout()` を使用して、 | ||
| 指定したミリ秒後に | ||
| コードの実行をスケジュールすることができます。 | ||
| この関数はブラウザの JavaScript API の [`window.setTimeout()`](https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout)に似ていますが、 | ||
| コードの文字列を渡して実行することはできません。 | ||
|
|
||
| `setTimeout()` は、最初の引数として実行する関数と、 | ||
| 2番目の引数として数値として定義されたミリ秒の遅延を受け入れます。 | ||
| 追加の引数も含めることができ、これらは関数に渡されます。 | ||
| これはその一例です: | ||
|
|
||
| ```js | ||
| function myFunc(arg) { | ||
| console.log(`arg was => ${arg}`); | ||
| } | ||
|
|
||
| setTimeout(myFunc, 1500, 'funky'); | ||
| ``` | ||
|
|
||
| 上記の関数 `myFunc()` は、`setTimeout()` の呼び出しにより、 | ||
| 可能な限り 1500 ミリ秒 (または 1.5 秒) くらいで実行されます。 | ||
|
|
||
| 設定されたタイムアウト間隔は、 | ||
| その*正確な*ミリ秒数の後に実行することに依存することはできません。 | ||
| これは、イベントループをブロックまたは保留している他の実行コードがタイムアウトの実行を遅らせるためです。 | ||
| *唯一*保証されているのは、 | ||
| タイムアウトが宣言されたタイムアウト間隔より早く実行されないということです。 | ||
|
|
||
| `setTimeout()` は、設定されたタイムアウトを参照するために使用できる | ||
| `Timeout` オブジェクトを返します。 | ||
| この返されたオブジェクトを使用して、タイムアウトをキャンセル (下記の `clearTimeout()` を参照) し、 | ||
| 実行動作を変更 (下記の`unref()` を参照) することができます。 | ||
|
|
||
| <!-- | ||
| ### "Right after this" Execution ~ *`setImmediate()`* | ||
|
|
||
| `setImmediate()` will execute code at the end of the current event loop cycle. | ||
|
|
@@ -99,6 +159,50 @@ code has been scheduled to execute with `process.nextTick()`, the execution | |
| cannot be stopped, just like with a normal function. Refer to [this guide](/en/docs/guides/event-loop-timers-and-nexttick/#process-nexttick) | ||
| to better understand the operation of `process.nextTick()`. | ||
|
|
||
| --> | ||
| ### "この直後に" 実行する ~ *`setImmediate()`* | ||
|
|
||
| `setImmediate()` は現在のイベントループサイクルの終わりにコードを実行します。 | ||
| このコードは、現在のイベントループ内の I/O 操作の*後*、 | ||
| および次のイベントループのためにスケジュールされたタイマーの*前*に実行されます。 | ||
| このコードの実行は「この直後」に行われると考えることができます。 | ||
| つまり、`setImmediate()` 関数呼び出しに続くコードは、 | ||
| `setImmediate()`関数引数の前に実行されます。 | ||
|
|
||
| `setImmediate()` の最初の引数は実行する関数になります。 | ||
| それ以降の引数は、実行時に関数に渡されます。これが例です: | ||
|
|
||
| ```js | ||
| console.log('before immediate'); | ||
|
|
||
| setImmediate((arg) => { | ||
| console.log(`executing immediate: ${arg}`); | ||
| }, 'so immediate'); | ||
|
|
||
| console.log('after immediate'); | ||
| ``` | ||
|
|
||
| `setImmediate()` に渡された上記の関数は、すべての実行可能コードが実行された後に実行され、 | ||
| コンソール出力は次のようになります: | ||
|
|
||
| ``` | ||
| before immediate | ||
| after immediate | ||
| executing immediate: so immediate | ||
| ``` | ||
|
|
||
| `setImmediate()` は `Immediate` オブジェクトを返します。 | ||
| これを使用して、スケジュールされた Immediate をキャンセル (下記の `clearImmediate()` を参照) できます。 | ||
|
|
||
| Note: Don't get `setImmediate()` confused with `process.nextTick()`. There are | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. この辺はこのままいく感じですか
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ちょっと中途半端感がありますね。途中までやるとしても"Clearing the Future"の前までやるとかですかね…。 |
||
| some major ways they differ. The first is that `process.nextTick()` will run | ||
| *before* any `Immediate`s that are set as well as before any scheduled I/O. | ||
| The second is that `process.nextTick()` is non-clearable, meaning once | ||
| code has been scheduled to execute with `process.nextTick()`, the execution | ||
| cannot be stopped, just like with a normal function. Refer to [this guide](/en/docs/guides/event-loop-timers-and-nexttick/#process-nexttick) | ||
| to better understand the operation of `process.nextTick()`. | ||
|
|
||
| <!-- | ||
| ### "Infinite Loop" Execution ~ *`setInterval()`* | ||
|
|
||
| If there is a block of code that should execute multiple times, `setInterval()` | ||
|
|
@@ -123,6 +227,32 @@ milliseconds, or 1.5 seconds, until it is stopped (see below). | |
| Just like `setTimeout()`, `setInterval()` also returns a `Timeout` object which | ||
| can be used to reference and modify the interval that was set. | ||
|
|
||
| --> | ||
| ### "Infinite Loop" Execution ~ *`setInterval()`* | ||
|
|
||
| If there is a block of code that should execute multiple times, `setInterval()` | ||
| can be used to execute that code. `setInterval()` takes a function | ||
| argument that will run an infinite number of times with a given millisecond | ||
| delay as the second argument. Just like `setTimeout()`, additional arguments | ||
| can be added beyond the delay, and these will be passed on to the function call. | ||
| Also like `setTimeout()`, the delay cannot be guaranteed because of operations | ||
| that may hold on to the event loop, and therefore should be treated as an | ||
| approximate delay. See the below example: | ||
|
|
||
| ```js | ||
| function intervalFunc() { | ||
| console.log('Cant stop me now!'); | ||
| } | ||
|
|
||
| setInterval(intervalFunc, 1500); | ||
| ``` | ||
| In the above example, `intervalFunc()` will execute about every 1500 | ||
| milliseconds, or 1.5 seconds, until it is stopped (see below). | ||
|
|
||
| Just like `setTimeout()`, `setInterval()` also returns a `Timeout` object which | ||
| can be used to reference and modify the interval that was set. | ||
|
|
||
| <!-- | ||
| ## Clearing the Future | ||
|
|
||
| What can be done if a `Timeout` or `Immediate` object needs to be cancelled? | ||
|
|
@@ -151,6 +281,36 @@ clearImmediate(immediateObj); | |
| clearInterval(intervalObj); | ||
| ``` | ||
|
|
||
| --> | ||
| ## Clearing the Future | ||
|
|
||
| What can be done if a `Timeout` or `Immediate` object needs to be cancelled? | ||
| `setTimeout()`, `setImmediate()`, and `setInterval()` return a timer object | ||
| that can be used to reference the set `Timeout` or `Immediate` object. | ||
| By passing said object into the respective `clear` function, execution of | ||
| that object will be halted completely. The respective functions are | ||
| `clearTimeout()`, `clearImmediate()`, and `clearInterval()`. See the example | ||
| below for an example of each: | ||
|
|
||
| ```js | ||
| const timeoutObj = setTimeout(() => { | ||
| console.log('timeout beyond time'); | ||
| }, 1500); | ||
|
|
||
| const immediateObj = setImmediate(() => { | ||
| console.log('immediately executing immediate'); | ||
| }); | ||
|
|
||
| const intervalObj = setInterval(() => { | ||
| console.log('interviewing the interval'); | ||
| }, 500); | ||
|
|
||
| clearTimeout(timeoutObj); | ||
| clearImmediate(immediateObj); | ||
| clearInterval(intervalObj); | ||
| ``` | ||
|
|
||
| <!-- | ||
| ## Leaving Timeouts Behind | ||
|
|
||
| Remember that `Timeout` objects are returned by `setTimeout` and `setInterval`. | ||
|
|
@@ -183,6 +343,49 @@ setImmediate(() => { | |
| timerObj.ref(); | ||
| }); | ||
| ``` | ||
| --> | ||
| ## Leaving Timeouts Behind | ||
|
|
||
| Remember that `Timeout` objects are returned by `setTimeout` and `setInterval`. | ||
| The `Timeout` object provides two functions intended to augment `Timeout` | ||
| behavior with `unref()` and `ref()`. If there is a `Timeout` object scheduled | ||
| using a `set` function, `unref()` can be called on that object. This will change | ||
| the behavior slightly, and not call the `Timeout` object *if it is the last | ||
| code to execute*. The `Timeout` object will not keep the process alive, waiting | ||
| to execute. | ||
|
|
||
| In similar fashion, a `Timeout` object that has had `unref()` called on it | ||
| can remove that behavior by calling `ref()` on that same `Timeout` object, | ||
| which will then ensure its execution. Be aware, however, that this does | ||
| not *exactly* restore the initial behavior for performance reasons. See | ||
| below for examples of both: | ||
|
|
||
| ```js | ||
| const timerObj = setTimeout(() => { | ||
| console.log('will i run?'); | ||
| }); | ||
|
|
||
| // if left alone, this statement will keep the above | ||
| // timeout from running, since the timeout will be the only | ||
| // thing keeping the program from exiting | ||
| timerObj.unref(); | ||
|
|
||
| // we can bring it back to life by calling ref() inside | ||
| // an immediate | ||
| setImmediate(() => { | ||
| timerObj.ref(); | ||
| }); | ||
| ``` | ||
| <!-- | ||
| ## Further Down the Event Loop | ||
|
|
||
| There's much more to the Event Loop and Timers than this guide | ||
| has covered. To learn more about the internals of the Node.js | ||
| Event Loop and how Timers operate during execution, check out | ||
| this Node.js guide: [The Node.js Event Loop, Timers, and | ||
| process.nextTick()](/en/docs/guides/event-loop-timers-and-nexttick/). | ||
|
|
||
| --> | ||
| ## Further Down the Event Loop | ||
|
|
||
| There's much more to the Event Loop and Timers than this guide | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
下で「タイマーをインポート」とか言っているので、ここもタイマーモジュールでいいと思いました。