| 1 | package SPVM::UV::Loop; | ||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | 1; | ||
| 6 | |||
| 7 | =encoding utf8 | ||
| 8 | |||
| 9 | =head1 Name | ||
| 10 | |||
| 11 | L<SPVM::UV::Loop|SPVM::UV::Loop> - libuv Event Loop | ||
| 12 | |||
| 13 | =head1 Description | ||
| 14 | |||
| 15 | C<UV::Loop> class in L<SPVM> represents an event loop in L<libuv|https://libuv.org/>. | ||
| 16 | |||
| 17 | =head1 Usage | ||
| 18 | |||
| 19 | use UV::Loop; | ||
| 20 | use UV::Constant as UV_C; | ||
| 21 | |||
| 22 | my $uv_loop = UV::Loop->new; | ||
| 23 | |||
| 24 | $uv_loop->run(UV_C->UV_RUN_DEFAULT); | ||
| 25 | |||
| 26 | =head1 Fields | ||
| 27 | |||
| 28 | =head2 uv_handles_h | ||
| 29 | |||
| 30 | C<has uv_handles_h : Hash of L<UV::Handle|SPVM::UV::Handle>;> | ||
| 31 | |||
| 32 | A hash that holds active handles associated with this event loop. | ||
| 33 | |||
| 34 | =head1 Class Methods | ||
| 35 | |||
| 36 | =head2 new | ||
| 37 | |||
| 38 | C<static method new : L<UV::Loop|SPVM::UV::Loop> ();> | ||
| 39 | |||
| 40 | Creates a new L<libuv loop|https://docs.libuv.org/en/v1.x/loop.html#c.uv_loop_init>. | ||
| 41 | |||
| 42 | Exceptions: | ||
| 43 | |||
| 44 | If C<uv_loop_init> fails, an exception is thrown.=head1 Instance Methods | ||
| 45 | |||
| 46 | =head2 run | ||
| 47 | |||
| 48 | C<method run : int ($uv_run_mode : int);> | ||
| 49 | |||
| 50 | Runs the event loop with the specified mode, and returns the return value of L<uv_run|https://docs.libuv.org/en/v1.x/loop.html#c.uv_run>. | ||
| 51 | |||
| 52 | See L<UV::Constant|SPVM::UV::Constant> for constants such as C<UV_RUN_XXX> specified at $uv_run_mode. | ||
| 53 | |||
| 54 | =head2 idle_init | ||
| 55 | |||
| 56 | C<method idle_init : void ($uv_idle : L<UV::Handle::Idle|SPVM::UV::Handle::Idle>);> | ||
| 57 | |||
| 58 | Initializes an idle handle $uv_idle associated with the event loop. See L<uv_idle_init|https://docs.libuv.org/en/v1.x/idle.html#c.uv_idle_init>. | ||
| 59 | |||
| 60 | Exceptions: | ||
| 61 | |||
| 62 | $uv_idle must be defined. Otherwise an exception is thrown. | ||
| 63 | |||
| 64 | =head2 timer_init | ||
| 65 | |||
| 66 | C<method timer_init : void ($uv_timer : L<UV::Handle::Timer|SPVM::UV::Handle::Timer>);> | ||
| 67 | |||
| 68 | Initializes a timer handle $uv_timer associated with the event loop. See L<uv_timer_init|https://docs.libuv.org/en/v1.x/timer.html#c.uv_timer_init>. | ||
| 69 | |||
| 70 | Exceptions: | ||
| 71 | |||
| 72 | $uv_timer must be defined. Otherwise an exception is thrown. | ||
| 73 | |||
| 74 | If C<uv_timer_init> fails, an exception is thrown. | ||
| 75 | |||
| 76 | =head2 poll_init | ||
| 77 | |||
| 78 | C<method poll_init : void ($uv_poll : L<UV::Handle::Poll|SPVM::UV::Handle::Poll>, $fd : int);> | ||
| 79 | |||
| 80 | Initializes a poll handle $uv_poll for the given file descriptor $fd associated with the event loop. See L<uv_poll_init|https://docs.libuv.org/en/v1.x/poll.html#c.uv_poll_init>. | ||
| 81 | |||
| 82 | Exceptions: | ||
| 83 | |||
| 84 | $uv_poll must be defined. Otherwise an exception is thrown. | ||
| 85 | |||
| 86 | If C<uv_poll_init> fails, an exception is thrown. | ||
| 87 | |||
| 88 | Exceptions: | ||
| 89 | |||
| 90 | $uv_async must be defined. Otherwise an exception is thrown. | ||
| 91 | |||
| 92 | $cb must be defined. Otherwise an exception is thrown. | ||
| 93 | |||
| 94 | If C<uv_async_init> fails, an exception is thrown. | ||
| 95 | |||
| 96 | =head2 async_init | ||
| 97 | |||
| 98 | C<method async_init : void ($uv_async : L<UV::Handle::Async|SPVM::UV::Handle::Async>, $cb : L<UV::Callback::Async|SPVM::UV::Callback::Async>);> | ||
| 99 | |||
| 100 | Initializes an async handle $uv_async associated with the event loop with a callback $cb. L<UV::Handle::Async#async_cb|SPVM::UV::Handle::Async/"async_cb"> field is set to $cb. See L<uv_async_init|https://docs.libuv.org/en/v1.x/async.html#c.uv_async_init>. | ||
| 101 | |||
| 102 | Exceptions: | ||
| 103 | |||
| 104 | $uv_pipe must be defined. Otherwise an exception is thrown. | ||
| 105 | |||
| 106 | If C<uv_pipe_init> fails, an exception is thrown. | ||
| 107 | |||
| 108 | =head2 pipe_init | ||
| 109 | |||
| 110 | C<method pipe_init : void ($uv_pipe : L<UV::Handle::Pipe|SPVM::UV::Handle::Pipe>, $ipc : int);> | ||
| 111 | |||
| 112 | Initializes a pipe handle $uv_pipe associated with the event loop with $ipc. See L<uv_pipe_init|https://docs.libuv.org/en/v1.x/pipe.html#c.uv_pipe_init>. | ||
| 113 | |||
| 114 | =head2 spawn | ||
| 115 | |||
| 116 | C<method spawn : int ($uv_process : L<UV::Handle::Process|SPVM::UV::Handle::Process>, $options : L<UV::ProcessOptions|SPVM::UV::ProcessOptions>);> | ||
| 117 | |||
| 118 | Spawns a process with the specified options associated with the event loop, and returns the return value of L<uv_spawn|https://docs.libuv.org/en/v1.x/process.html#c.uv_spawn>. | ||
| 119 | |||
| 120 | Exceptions: | ||
| 121 | |||
| 122 | $uv_process must be defined. Otherwise an exception is thrown. | ||
| 123 | |||
| 124 | $options must be defined. Otherwise an exception is thrown. | ||
| 125 | |||
| 126 | If C<uv_spawn> fails, an exception is thrown. | ||
| 127 | |||
| 128 | =head2 signal_init | ||
| 129 | |||
| 130 | C<method signal_init : void ($uv_signal : L<UV::Handle::Signal|SPVM::UV::Handle::Signal>);> | ||
| 131 | |||
| 132 | Initializes a signal handle $uv_signal associated with the event loop. See L<uv_signal_init|https://docs.libuv.org/en/v1.x/signals.html#c.uv_signal_init>. | ||
| 133 | |||
| 134 | Exceptions: | ||
| 135 | |||
| 136 | $uv_signal must be defined. Otherwise an exception is thrown. | ||
| 137 | |||
| 138 | If C<uv_signal_init> fails, an exception is thrown. | ||
| 139 | |||
| 140 | =head2 DESTROY | ||
| 141 | |||
| 142 | C<method DESTROY : void ();> | ||
| 143 | |||
| 144 | Destroys the event loop and releases its resources. See L<uv_loop_close|https://docs.libuv.org/en/v1.x/loop.html#c.uv_loop_close>. | ||
| 145 | |||
| 146 | Exceptions: | ||
| 147 | |||
| 148 | If C<uv_loop_close> fails, an exception is thrown. |