Node.js Timers Module
Voorbeeld
Skryf "Hallo" elke 500 millisekondes:
var myInt = setInterval(function () {
console.log("Hello");
}, 500);
Definisie en gebruik
Die Timers-module bied 'n manier om funksies te skeduleer om later op 'n gegewe tydstip opgeroep te word.
Die Timer-voorwerp is 'n globale voorwerp in Node.js, en dit is nie nodig om dit in te voer deur die require
sleutelwoord in te voer nie.
Timers Metodes
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. |