Modulo timer Node.js

❮ Moduli integrati


Esempio

Scrivi "Ciao" ogni 500 millisecondi:

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

Definizione e utilizzo

Il modulo Timer fornisce un modo per programmare le funzioni da richiamare in un momento successivo.

L'oggetto Timer è un oggetto globale in Node.js e non è necessario importarlo utilizzando la requireparola chiave.


Metodi dei timer

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.

❮ Moduli integrati