Moduł liczników Node.js

❮ Wbudowane moduły


Przykład

Pisz „Cześć” co 500 milisekund:

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

Definicja i użycie

Moduł Timers zapewnia sposób planowania funkcji, które mają być wywoływane później w określonym czasie.

Obiekt Timer jest obiektem globalnym w Node.js i nie trzeba go importować za pomocą requiresłowa kluczowego.


Metody timerów

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.

❮ Wbudowane moduły