class Timer
package thx
Timer provides several meaning to delay the execution of code. At the moment it is only
implemented for platforms that have a native concept of Timer like Swf and JavaScript or c++/Neko
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 methods
staticdebounce (callback:Void ‑> Void, delayms:Int, leading:Bool = false):Void ‑> Void
Creates a function that delays the execution of callback by delayms every time it is
invoked. If leading is set to true, a first execution is guaranteed to happen as soon
as the returnd function is invoked.
staticdelay (callback:Void ‑> Void, delayms:Int):Void ‑> Void
Timer.delay invokes callback after delayms milliseconds. The scheduling can be
canelled using the returned cancel function.
staticframe (callback:Float ‑> Void):Void ‑> Void
Invokes callback at every frame using native implementation where available. A delta time
in milliseconds is passed since the latest time callback was invoked.
staticimmediate (callback:Void ‑> Void):Void ‑> Void
Timer.immediate works essentially like Timer.delay with the exception that the delay
will be the shortest allowed by the platform. How short the delay depends a lot on
the target platform.
staticnextFrame (callback:Void ‑> Void):Void ‑> Void
Delays callback untile the next frame using native implementation where available.
staticrepeat (callback:Void ‑> Void, delayms:Int):Void ‑> Void
Timer.repeat continues to invoke callback until it is cancelled using the returned
cancel function.
staticthrottle (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.
staticinline 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.