Main.hx 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. class Main {
  2. static function main() {
  3. var event : haxe.MainLoop.MainEvent = null;
  4. var count = 0;
  5. event = haxe.MainLoop.add(function() {
  6. trace(count++);
  7. if( count == 10 ) {
  8. event.stop();
  9. trace(haxe.MainLoop.hasEvents());
  10. }
  11. });
  12. #if sys
  13. // if we don't use native timer, this should execute before
  14. var t = new haxe.Timer(100);
  15. t.run = function() {
  16. trace("BEFORE1");
  17. t.stop();
  18. };
  19. #end
  20. var t = new haxe.Timer(200);
  21. var count = 0;
  22. t.run = function() {
  23. trace("T" + count++);
  24. if( count == 5 )
  25. t.stop();
  26. };
  27. #if sys
  28. // if we don't use native timer, this should execute before
  29. var t = new haxe.Timer(100);
  30. t.run = function() {
  31. trace("BEFORE2");
  32. t.stop();
  33. };
  34. #end
  35. #if sys
  36. Sys.sleep(0.3);
  37. #end
  38. haxe.MainLoop.addThread(function() {
  39. var event : haxe.MainLoop.MainEvent = null;
  40. var count = 0;
  41. event = haxe.MainLoop.add(function() {
  42. trace(String.fromCharCode("A".code + count++));
  43. if( count == 5 ) event.stop();
  44. });
  45. #if sys
  46. Sys.sleep(3);
  47. #end
  48. });
  49. }
  50. }