Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is "setTimeout" from JavaScript in Haxe?

Tags:

haxe

Is there an implementation of setTimeout() and clearTimeout() in Haxe? It's of course possible to use the Timer class, but for a one-shot execution it's not the best way, I guess.

like image 553
nepa Avatar asked Sep 29 '11 06:09

nepa


1 Answers

For a one-shot execution I think that Timer.delay() is perfect. You can use the returned instance to stop the timer later:

var timer = haxe.Timer.delay(function() trace("Hello World!"), 250);
...
timer.stop();

You could also access the native setTimeout() with the js.html.Window extern:

var handle = js.Browser.window.setTimeout(function() trace("Hello World!"), 250);
...
js.Browser.window.clearTimeout(handle);
like image 149
Franco Ponticelli Avatar answered Sep 21 '22 15:09

Franco Ponticelli