| 1 | package SPVM::UV::Handle::Timer; | ||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | 1; | ||
| 6 | |||
| 7 | =encoding utf8 | ||
| 8 | |||
| 9 | =head1 Name | ||
| 10 | |||
| 11 | SPVM::UV::Handle::Timer - Timer Handle for libuv | ||
| 12 | |||
| 13 | =head1 Description | ||
| 14 | |||
| 15 | C<UV::Handle::Timer> in L<SPVM> represents the timer handle for L<libuv|https://libuv.org/>, corresponding to the C<uv_timer_t> structure. | ||
| 16 | |||
| 17 | =head1 Super Class | ||
| 18 | |||
| 19 | L<UV::Handle|SPVM::UV::Handle> | ||
| 20 | |||
| 21 | =head1 Usage | ||
| 22 | |||
| 23 | use UV::Handle::Timer; | ||
| 24 | |||
| 25 | my $timer = UV::Handle::Timer->new; | ||
| 26 | |||
| 27 | =head1 Fields | ||
| 28 | |||
| 29 | =head2 timer_cb | ||
| 30 | |||
| 31 | C<has timer_cb : rw L<UV::Callback::Timer|SPVM::UV::Callback::Timer>;> | ||
| 32 | |||
| 33 | The callback called when the timer timeout expires. | ||
| 34 | |||
| 35 | =head1 Class Methods | ||
| 36 | |||
| 37 | =head2 new | ||
| 38 | |||
| 39 | C<static method new : L<UV::Handle::Timer|SPVM::UV::Handle::Timer> ();> | ||
| 40 | |||
| 41 | Creates a new L<UV::Handle::Timer|SPVM::UV::Handle::Timer> object, and returns it. | ||
| 42 | |||
| 43 | =head1 Instance Methods | ||
| 44 | |||
| 45 | =head2 start | ||
| 46 | |||
| 47 | C<method start : void ($cb : L<UV::Callback::Timer|SPVM::UV::Callback::Timer>, $timeout_msec : long, $interval_msec : long = 0);> | ||
| 48 | |||
| 49 | Starts the timer with a timeout of C<$timeout_msec> milliseconds and a repeat interval of C<$interval_msec> milliseconds. | ||
| 50 | |||
| 51 | The callback C<$cb> is stored in L</"timer_cb"> field. | ||
| 52 | |||
| 53 | The callback C<$cb> is invoked when the timer timeout expires. | ||
| 54 | |||
| 55 | This method calls the L<uv_timer_start|https://docs.libuv.org/en/v1.x/timer.html#c.uv_timer_start> function internally. | ||
| 56 | |||
| 57 | Exceptions: | ||
| 58 | |||
| 59 | If $cb is not defined, an exception is thrown. | ||
| 60 | |||
| 61 | If uv_timer_start fails, an exception is thrown. | ||
| 62 | |||
| 63 | =head2 stop | ||
| 64 | |||
| 65 | C<method stop : void ();> | ||
| 66 | |||
| 67 | Stops the timer. | ||
| 68 | |||
| 69 | This method calls the L<uv_timer_stop|https://docs.libuv.org/en/v1.x/timer.html#c.uv_timer_stop> function internally. | ||
| 70 | |||
| 71 | Exceptions: | ||
| 72 | |||
| 73 | If uv_timer_stop fails, an exception is thrown. | ||
| 74 | |||
| 75 | =head2 again | ||
| 76 | |||
| 77 | C<method again : void ();> | ||
| 78 | |||
| 79 | Start the timer if it has a repeat value set. | ||
| 80 | |||
| 81 | This method calls the L<uv_timer_again|https://docs.libuv.org/en/v1.x/timer.html#c.uv_timer_again> function internally. | ||
| 82 | |||
| 83 | Exceptions: | ||
| 84 | |||
| 85 | If uv_timer_again fails, an exception is thrown. | ||
| 86 | |||
| 87 | =head1 Copyright & License | ||
| 88 | |||
| 89 | Copyright (c) 2026 Yuki Kimoto | ||
| 90 | |||
| 91 | MIT License |