Node.jsタイマーモジュール

❮内蔵モジュール


500ミリ秒ごとに「Hello」と書き込みます。

var myInt = setInterval(function () {
    console.log("Hello");
}, 500);

定義と使用法

タイマーモジュールは、指定された時間に後で呼び出される関数をスケジュールする方法を提供します。

requireTimerオブジェクトはNode.jsのグローバルオブジェクトであり、キーワードを使用してインポートする必要はありません。


タイマーメソッド

Method Description
clearImmediate() Cancels an Immediate object
clearInterval() Cancels an Interval object
clearTimeout() Cancels a Timeout object
ref() Makes the Timeout object active. Will only have an effect if the Timeout.unref() method has been called to make the Timeout object inactive.
setImmediate() Executes a given function immediately.
setInterval() Executes a given function at every given milliseconds
setTimeout() Executes a given function after a given time (in milliseconds)
unref() Stops the Timeout object from remaining active.

❮内蔵モジュール