Módulo de temporizadores Node.js

❮ Módulos integrados


Exemplo

Escreva "Olá" a cada 500 milissegundos:

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

Definição e uso

O módulo Timers fornece uma maneira de agendar funções para serem chamadas posteriormente em um determinado momento.

O objeto Timer é um objeto global no Node.js e não é necessário importá-lo usando a palavra- requirechave.


Métodos de temporizadores

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.

❮ Módulos integrados