Loop.hx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /**
  28. Returns the default event loop.
  29. **/
  30. static public function defaultLoop():Loop;
  31. /**
  32. Allocates and initializes a new event loop.
  33. **/
  34. static public function init():Result<Loop>;
  35. /**
  36. Releases any state libuv is holding on to.
  37. Normally there's no need to do this manually.
  38. Warning! Only call `Loop.libraryShutdown()` once.
  39. Warning! Don’t call `Loop.libraryShutdown()` when there are still event loops or I/O requests active.
  40. Warning! Don’t call libuv functions after calling `Loop.libraryShutdown()`.
  41. **/
  42. static public function libraryShutdown():Void;
  43. /**
  44. Runs an event loop.
  45. **/
  46. public function run(mode:RunMode):Bool;
  47. /**
  48. Releases resources associated with an event loop.
  49. **/
  50. public function close():Result<Result.NoData>;
  51. /**
  52. Indicates whether the loop is monitoring any activity.
  53. **/
  54. public function alive():Bool;
  55. /**
  56. Stops an event loop as soon as possible.
  57. **/
  58. public function stop():Void;
  59. /**
  60. Returns the cached loop timestamp.
  61. **/
  62. public function now():eval.integers.UInt64;
  63. /**
  64. Updates the cached loop timestamp.
  65. **/
  66. public function updateTime():Void;
  67. /**
  68. Sets the loop option.
  69. **/
  70. public function configure<T>(option:LoopOption<T>, value:T):Result<Result.NoData>;
  71. }