haXe API Documentation
Back | Index
class haxe.Timer
Available in flash8, neko, js, flash, php, cpp

The Timer class allows you to create asynchronous timers on platforms that support events.

The intended usage is to create an instance of the Timer class with a given interval, set its run() method to a custom function to be invoked and eventually call stop() to stop the Timer.

It is also possible to extend this class and override its run() method in the child class.

function new(time_ms : Int) : Void
Available in flash8, js, flash

Creates a new timer that will run every time_ms milliseconds.

After creating the Timer instance, it calls this.run() repeatedly, with delays of time_ms milliseconds, until this.stop() is called.

The first invocation occurs after time_ms milliseconds, not immediately.

The accuracy of this may be platform-dependent.

dynamic function run() : Void
Available in flash8, js, flash
function stop() : Void
Available in flash8, js, flash
static function delay(f : Void -> Void, time_ms : Int) : Timer
Available in flash8, js, flash
static function measure<T>(f : Void -> T, ?pos : PosInfos) : T
Available in neko, php, cpp

Measures the time it takes to execute f, in seconds with fractions.

This is a convenience function for calculating the difference between Timer.stamp() before and after the invocation of f.

The difference is passed as argument to Log.trace(), with "s" appended to denote the unit. The optional pos argument is passed through.

If f is null, the result is unspecified.

static function measure<T>(f : Void -> T, ?pos : PosInfos) : T
Available in flash8, js, flash
static function stamp() : Float
Back | Index