Files
Hristo Deshev 437e220c42 Zone-aware versions of certain APIs: setTimeout/setInterval mostly.
Instead of waiting for zone.js to patch our global declarations and break
the lazy module loading optimizations there, we'll let it patch stuff
before "globals" gets loaded, so that it doesn't touch (and break) the code
there.

Of course, that requires that functions that need legit patching need to be
made aware of the zone, or get patched later on. The global.zonedCallback
function makes that easy, and we use it for setTimeout/setInterval.
2016-03-31 18:29:42 +03:00
..
2014-05-12 13:38:17 +03:00
2015-03-03 10:34:40 +02:00

Timer module. Functions also can be availble in the global context if you require globals module.

    require("globals");

	setTimeout(function(){ log("Test"); }, 2000);

	var id = setTimeout(function(){ log("Test"); }, 2000);
	...
	clearTimeout(id);

	setInterval(function(){ log("Test"); }, 2000);

	var intervalId = setInterval(function(){ log("Test"); }, 2000);
	...
	clearInterval(intervalId)

OR

    var timer = require("timer");

	timer.setTimeout(function(){ log("Test"); }, 2000);

	var id = timer.setTimeout(function(){ log("Test"); }, 2000);
	...
	timer.clearTimeout(id);

	timer.setInterval(function(){ log("Test"); }, 2000);

	var intervalId = timer.setInterval(function(){ log("Test"); }, 2000);
	...
	timer.clearInterval(intervalId)

The second parameter for setTimeout and setInterval is optional with default value of 0.