Loop.hx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package eval.luv;
  2. enum abstract RunMode(Int) {
  3. /** Runs the event loop until there are no more active and referenced handles or requests. */
  4. var DEFAULT = 0;
  5. /** Poll for i/o once. Note that this mode blocks if there are no pending callbacks. */
  6. var ONCE = 1;
  7. /** Poll for i/o once but don't block if there are no pending callbacks. */
  8. var NOWAIT = 2;
  9. }
  10. /**
  11. Configuration options.
  12. @see http://docs.libuv.org/en/v1.x/loop.html#c.uv_loop_configure
  13. **/
  14. enum abstract LoopOption<T>(Int) {
  15. extern static public final sigprof:Int;
  16. var LOOP_BLOCK_SIGNAL:LoopOption<Int> = 0;
  17. var METRICS_IDLE_TIME:LoopOption<Result.NoData> = 1;
  18. }
  19. /**
  20. Event loops.
  21. @see https://aantron.github.io/luv/luv/Luv/Loop
  22. Haxe event loops define an implicit cast to libuv loops. That is, you can use
  23. `sys.thread.Thread.current().events` in any place where `eval.luv.Loop` is
  24. expected.
  25. **/
  26. @:coreType abstract Loop {
  27. @:from
  28. static inline function fromHaxeEventLoop(events:sys.thread.EventLoop):Loop {
  29. return events.handle;
  30. }
  31. /**
  32. Returns the default event loop.
  33. **/
  34. static public function defaultLoop():Loop;
  35. /**
  36. Allocates and initializes a new event loop.
  37. **/
  38. static public function init():Result<Loop>;
  39. /**
  40. Releases any state libuv is holding on to.
  41. Normally there's no need to do this manually.
  42. Warning! Only call `Loop.libraryShutdown()` once.
  43. Warning! Don’t call `Loop.libraryShutdown()` when there are still event loops or I/O requests active.
  44. Warning! Don’t call libuv functions after calling `Loop.libraryShutdown()`.
  45. **/
  46. static public function libraryShutdown():Void;
  47. /**
  48. Runs an event loop.
  49. **/
  50. public function run(mode:RunMode):Bool;
  51. /**
  52. Releases resources associated with an event loop.
  53. **/
  54. public function close():Result<Result.NoData>;
  55. /**
  56. Indicates whether the loop is monitoring any activity.
  57. **/
  58. public function alive():Bool;
  59. /**
  60. Stops an event loop as soon as possible.
  61. **/
  62. public function stop():Void;
  63. /**
  64. Returns the cached loop timestamp.
  65. **/
  66. public function now():eval.integers.UInt64;
  67. /**
  68. Updates the cached loop timestamp.
  69. **/
  70. public function updateTime():Void;
  71. /**
  72. Sets the loop option.
  73. **/
  74. public function configure<T>(option:LoopOption<T>, value:T):Result<Result.NoData>;
  75. }