Node.js 타이머 모듈

❮ 내장 모듈


예시

500밀리초마다 "Hello" 쓰기:

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

정의 및 사용

Timers 모듈은 주어진 시간에 나중에 호출되도록 함수를 예약하는 방법을 제공합니다.

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.

❮ 내장 모듈