LoginSignup
1
1

More than 3 years have passed since last update.

Node.js で無限ループしつつ、一定周期で処理をしたい

Posted at

メモ。
Node.js で無限ループしつつ、一定周期で処理をしたいという要件があった。
(具体的には SIGTERM シグナルを受けてから1秒毎に標準出力に文字列を出力したい)
上記について Node.js のサイトにずばり書いてあった。

"Infinite Loop" Execution ~ setInterval()

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

setInterval(intervalFunc, 1500);

この場合、1.5秒毎に intervalFunc() が実行される。
必要に応じて時間や処理内容を変えれば良い。

Node.js v10.17.0 で動作確認済み。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1