Skip to content

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
merged 82 commits into from
Aug 3, 2019
Merged
Changes from all 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 May 11, 2019
17fd5cf
translate to japanese contribute.md.
silverskyvicto May 11, 2019
8e9fe26
translate to japanese code-and-learn.md.
silverskyvicto May 11, 2019
c2f14c2
translate to japanese node-events.md.
silverskyvicto May 11, 2019
78b96fe
ranslate to japanese collab-summit.md.
silverskyvicto May 11, 2019
d014002
translate to japanese node-meetups.md.
silverskyvicto May 11, 2019
1e87896
translate to japanese node-speakers.md.
silverskyvicto May 11, 2019
716c8d6
translate title
silverskyvicto May 11, 2019
df0e63b
translate dependencies.md in Japanese.
silverskyvicto May 11, 2019
08853a6
List translation is unnecessary.
silverskyvicto May 12, 2019
2deeb95
Translation is unnecessary except for title.
silverskyvicto May 12, 2019
f746e2e
translate japanese.
silverskyvicto May 12, 2019
3b6d45a
fix japanese translation.
silverskyvicto May 12, 2019
72d8a18
fixed translation style.
silverskyvicto May 13, 2019
b16c9b1
fixed dependencies.md translation style.
silverskyvicto May 13, 2019
a368812
fixed debugging-getting-started translation style.
silverskyvicto May 13, 2019
774bd16
Update locale/ja/get-involved/collab-summit.md
silverskyvicto May 13, 2019
7fc2402
Update locale/ja/get-involved/code-and-learn.md
silverskyvicto May 13, 2019
0df90e4
Update locale/ja/get-involved/collab-summit.md
silverskyvicto May 13, 2019
616df0d
fixed simple-profiling.md translation style.
silverskyvicto May 13, 2019
eac7cab
translate a part of diagnostics-flamegraph.md
silverskyvicto May 13, 2019
c5b269e
fixed a part of collab-summit translation.
silverskyvicto May 13, 2019
c149d1a
Merge branch 'translate/ja' of github.com:silverskyvicto/nodejs.org i…
silverskyvicto May 13, 2019
6eeb46d
Update locale/ja/docs/guides/debugging-getting-started.md
silverskyvicto May 14, 2019
35aa9ff
fixed review point.
silverskyvicto May 14, 2019
e125017
fixed review point.
silverskyvicto May 16, 2019
a3f1e9e
Update locale/ja/docs/guides/diagnostics-flamegraph.md
silverskyvicto May 16, 2019
f4c68fe
Merge branch 'translate/guide' of github.com:silverskyvicto/nodejs.or…
silverskyvicto May 16, 2019
35920ab
fixed review point.
silverskyvicto May 17, 2019
75f64cf
translate before "Why do I need them at all?"
silverskyvicto May 17, 2019
62a1ac6
Merge branch 'master' of https://github.com/silverskyvicto/nodejs.org…
silverskyvicto May 22, 2019
23aed62
Merge branch 'master' of https://github.com/silverskyvicto/nodejs.org…
silverskyvicto May 22, 2019
5e6cd2f
Merge branch 'translate/guide'
silverskyvicto May 22, 2019
dd0bc4e
translate japanese.
silverskyvicto May 25, 2019
9759b07
Merge branch 'translate/guide' of github.com:silverskyvicto/nodejs.or…
silverskyvicto May 25, 2019
8a54033
translate into japanese.
silverskyvicto May 25, 2019
0814347
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto May 26, 2019
84851ed
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto May 26, 2019
d9d0b25
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto May 26, 2019
668698f
Merge branch 'master' of github.com:silverskyvicto/nodejs.org
silverskyvicto May 26, 2019
60d3aef
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto May 26, 2019
d4757c2
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto May 26, 2019
84fc9c1
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto May 26, 2019
baf3e5f
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto May 26, 2019
6a2cf83
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto May 26, 2019
4357f22
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto May 26, 2019
c69b852
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto May 26, 2019
7396b82
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto May 26, 2019
f6956ba
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto May 26, 2019
acfa793
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto May 26, 2019
868e43e
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto May 26, 2019
5f0a972
Update locale/ja/docs/guides/nodejs-docker-webapp.md
silverskyvicto May 26, 2019
33c8e9a
translate before Phase2
silverskyvicto May 26, 2019
8391208
translate first polyfill
silverskyvicto May 26, 2019
600d062
Merge branch 'translate/guide' of github.com:silverskyvicto/nodejs.or…
silverskyvicto May 26, 2019
77225bd
Merge remote-tracking branch 'upstream/master'
silverskyvicto May 29, 2019
f2d9018
fixed review point
silverskyvicto May 29, 2019
13daa31
Merge branch 'translate/guide'
silverskyvicto May 30, 2019
e408a36
Merge branch 'master' of https://github.com/nodejs/nodejs.org
silverskyvicto May 30, 2019
3420875
Merge remote-tracking branch 'upstream/master'
silverskyvicto May 31, 2019
b658878
Merge branch 'master' of github.com:silverskyvicto/nodejs.org
silverskyvicto May 31, 2019
9bd9806
Merge remote-tracking branch 'upstream/master' into translate/guide
silverskyvicto May 31, 2019
f63805e
translate one list item.
silverskyvicto May 31, 2019
5504f68
Merge branch 'master' of https://github.com/nodejs/nodejs.org
silverskyvicto Jun 3, 2019
8c17d75
Merge remote-tracking branch 'upstream/master'
silverskyvicto Jun 15, 2019
90c1af2
Merge branch 'master' of github.com:silverskyvicto/nodejs.org
silverskyvicto Jun 15, 2019
2efad39
translate one list item.
silverskyvicto May 31, 2019
6bd0d63
Merge branch 'translate/guide' of github.com:silverskyvicto/nodejs.or…
silverskyvicto Jun 15, 2019
56fa9e1
translate before variant 3.
silverskyvicto Jun 15, 2019
399cf21
translate before Regarding `Buffer.allocUnsafe()`
silverskyvicto Jun 15, 2019
646c881
translate before faq.
silverskyvicto Jun 15, 2019
a2e2b56
translate to last.
silverskyvicto Jun 15, 2019
35c7588
translate blocking-vs-non-blocking into japanese.
silverskyvicto Jun 15, 2019
7acb7e9
Merge remote-tracking branch 'upstream/master'
silverskyvicto Jun 22, 2019
0164819
Merge remote-tracking branch 'upstream/master'
silverskyvicto Jul 26, 2019
e71b8b1
Translate middle of "setImmediate" into japanese.
silverskyvicto Jul 26, 2019
72b428a
Translate middle of "setImmediate" into japanese.
silverskyvicto Jul 26, 2019
8b70388
Merge branch 'translate/guide' of github.com:silverskyvicto/nodejs.or…
silverskyvicto Jul 26, 2019
da07eba
Fixed Review Point.
silverskyvicto Aug 1, 2019
47eceb1
Translate before "Leaving Timeouts Behind"
silverskyvicto Aug 1, 2019
a87a07e
Translate remained part.
silverskyvicto Aug 1, 2019
d98a95b
Fixed conjunction.
silverskyvicto Aug 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 204 additions & 1 deletion locale/ja/docs/guides/timers-in-node.md
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
Expand All @@ -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 のタイマーモジュールには、
一定期間後にコードを実行する関数が含まれています。
ブラウザの 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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()` を参照) できます。

注意: `setImmediate()` を `process.nextTick()` と混同しないでください。
いくつかの大きな違いがあります。
1つ目は、`process.nextTick()` は、設定されている `Immediate` やスケジュールされている I/O の*前*に実行されるということです。
2つ目は、`process.nextTick()` は消去不可能であるということです。
つまり、一度 `process.nextTick()` でコードを実行するようにスケジュールされると、
通常の関数のように実行を停止することはできません。
`process.nextTick()` の操作をよく理解するために[このガイド](/ja/docs/guides/event-loop-timers-and-nexttick/#process-nexttick)を参照してください。

<!--
### "Infinite Loop" Execution ~ *`setInterval()`*

If there is a block of code that should execute multiple times, `setInterval()`
Expand All @@ -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.

-->
### "無限ループ" 実行 ~ *`setInterval()`*

複数回実行する必要があるコードブロックがある場合、
`setInterval()` を使用してそのコードを実行できます。
`setInterval()` は2番目の引数として指定されたミリ秒の遅れで無限回実行する関数の引数を取ります。
`setTimeout()` と同じように、遅延を超えて追加の引数を追加することができ、
それらは関数呼び出しに渡されます。
`setTimeout()` と同様に、イベントループに耐えることができる操作のために遅延を保証することはできません。
したがっておおよその遅延として扱われるべきです。
以下の例を参照してください。

```js
function intervalFunc() {
console.log('Cant stop me now!');
}

setInterval(intervalFunc, 1500);
```
上の例では、`intervalFunc()` は停止されるまで
約 1500 ミリ秒 (1.5秒) ごとに実行されます(下記参照)。

`setTimeout()` と同様に、
`setInterval()` もまた設定された間隔を参照したり修正したりするのに使用できる `Timeout` オブジェクトを返します。

<!--
## Clearing the Future

What can be done if a `Timeout` or `Immediate` object needs to be cancelled?
Expand Down Expand Up @@ -151,6 +281,36 @@ clearImmediate(immediateObj);
clearInterval(intervalObj);
```

-->
## 未来をクリアする

`Timeout` または `Immediate` オブジェクトをキャンセルする必要がある場合はどうすればいいですか?
`setTimeout()`、`setImmediate()`、および `setInterval()` は、
set `Timeout`または `Immediate` オブジェクトを参照するために使用できるタイマーオブジェクトを返します。
前述のオブジェクトをそれぞれの `clear` 関数に渡すことによって、
そのオブジェクトの実行は完全に停止されます。
それぞれの関数は `clearTimeout()`、`clearImmediate()`、そして `clearInterval()` です。
それぞれの例については、以下の例を参照してください:

```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`.
Expand Down Expand Up @@ -183,10 +343,53 @@ setImmediate(() => {
timerObj.ref();
});
```
-->
## 後ろにタイムアウトを残す

`Timeout` オブジェクトは `setTimeout` と `setInterval` によって返されることを忘れないでください。
`Timeout` オブジェクトは `unref()` と `ref()` で `Timeout` の振る舞いを増強することを目的とした2つの関数を提供します。
`set` 関数を使ってスケジュールされた `Timeout` オブジェクトがあれば、
そのオブジェクトに対して `unref()` を呼び出すことができます。
これはふるまいをわずかに変えます、
そして*それが実行する最後のコードであるなら* `Timeout` オブジェクトを呼ばないでください。
`Timeout` オブジェクトはプロセスを実行し続け、実行するのを待ちません。

同様に、`unref()` が呼び出された `Timeout` オブジェクトは、
同じ `Timeout` オブジェクトに対して `ref()` を呼び出すことでその振る舞いを取り除くことができ、
それによってその実行が保証されます。
ただし、パフォーマンス上の理由から、これによって初期の動作が*正確*に復元されるわけではないことに注意してください。
両方の例については、以下を参照してください。

```js
const timerObj = setTimeout(() => {
console.log('will i run?');
});

// このままにしておくと、
// タイムアウトがプログラムの終了を妨げる唯一のものになるので、
// このステートメントで上記のタイムアウトを実行しないようにします。
timerObj.unref();

// immediate 内で ref() を呼び出すことでそれを元の状態に
// 戻すことができます。
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/).

-->
## イベントループのさらに下へ

このガイドでカバーしてきた以上に
イベントループとタイマーにはもっとたくさんのものがあります。
Node.js イベントループの内部と、
実行中のタイマーの動作の詳細については、
この Node.js ガイド [Node.js イベントループ、タイマー、および process.nextTick()](/ja/docs/guides/event-loop-timers-and-nexttick/) を参照してください。