Available on java, js, swf
Timer provides several meaning to delay the execution of code. At the moment it is only
with OpenFL or NME.
All of the Timer methods return a function with signature Void -> Void that can be used to cancel the timer.
// set the execution delayed by 200ms var cancel = Timer.delay(doSomethingLater, 200); // cancel immediately (doSomethingLater will never be executed) cancel();
Note that calling the cancel function multiple times have no effect after the first execution.
static function debounce(callback:Void -> Void, delayms:Int, leading:Bool = false):Void -> Void
Creates a function that delays the execution of
delayms every time it is
leading is set to true, a first execution is guaranteed to happen as soon
as the returnd function is invoked.
static function frame(callback:Float -> Void):Void -> Void
callback at every frame using native implementation where available. A delta time
in milliseconds is passed since the latest time callback was invoked.
static function nextFrame(callback:Void -> Void):Void -> Void
callback untile the next frame using native implementation where available.
static function resolution():Float
static function throttle(callback:Void -> Void, delayms:Int, leading:Bool = false):Void -> Void
The returned function executes
callback at most once every
delayms regardless of
how many times it is invoked in that timespance. Setting
leading to true ensures
that the callback is invoked at the beginning of the cycle.
static inline function time():Float
Returns a time value in milliseconds. Where supported, the decimal value represents microseconds.
Note that the initial value might change from platform to platform so only delta measurements make sense.