Loop.hx 895 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package hl.uv;
  2. enum abstract LoopRunMode(Int) {
  3. var Default = 0;
  4. var Once = 1;
  5. var NoWait = 2;
  6. }
  7. abstract Loop(hl.Abstract<"uv_loop">) {
  8. @:hlNative("uv","loop_close") public function close() : Int {
  9. return 0;
  10. }
  11. @:hlNative("uv","run") public function run( mode : LoopRunMode ) : Int {
  12. return 0;
  13. }
  14. @:hlNative("uv","loop_alive") public function alive() : Int {
  15. return 0;
  16. }
  17. @:hlNative("uv","stop") public function stop() : Void {
  18. }
  19. public static function getDefault() : Loop {
  20. var def = default_loop();
  21. if( loopEvent == null )
  22. loopEvent = haxe.MainLoop.add(function() {
  23. // if no more things to process, stop
  24. if( def.run(NoWait) == 0 ) {
  25. loopEvent.stop();
  26. loopEvent = null;
  27. }
  28. });
  29. return def;
  30. }
  31. @:hlNative("uv", "default_loop") static function default_loop() : Loop {
  32. return null;
  33. }
  34. static var loopEvent : haxe.MainLoop.MainEvent;
  35. }