NativeScript's global timer
variable lets you set timeouts and intervals for asynchronous delayed function calls.
Importing
var timer = require("timer")
Timeouts
var callback = function(){
console.log("I will be executed once after 500ms");
}
var timeoutId = timer.setTimeout(callback, 500);
// clearing the timeout
timer.clearTimeout(timeoutId);
Intervals
var callback = function(){
console.log("I will be executed every 500 ms")
}
var intervalId = timer.setInterval(callback, 500);
// clearing the interval
timer.clearInterval(intervalId);