uvw 3.1.0
Loading...
Searching...
No Matches
Public Member Functions | List of all members
uvw::timer_handle Class Referencefinal

The timer handle. More...

#include <timer.h>

Inheritance diagram for uvw::timer_handle:
Inheritance graph
[legend]
Collaboration diagram for uvw::timer_handle:
Collaboration graph
[legend]

Public Member Functions

int init () final
 Initializes the handle.
 
int start (time timeout, time repeat)
 Starts the timer.
 
int stop ()
 Stops the handle.
 
int again ()
 Stops the timer and restarts it if it was repeating.
 
void repeat (time repeat)
 Sets the repeat interval value.
 
time repeat ()
 Gets the timer repeat value.
 
time due_in ()
 Gets the timer due value.
 
- Public Member Functions inherited from uvw::handle< timer_handle, uv_timer_t, timer_event >
handle_category category () const noexcept
 Gets the category of the handle.
 
handle_type type () const noexcept
 Gets the type of the handle.
 
bool active () const noexcept
 Checks if the handle is active.
 
bool closing () const noexcept
 Checks if a handle is closing or closed.
 
void close () noexcept
 Request handle to be closed.
 
void reference () noexcept
 Reference the given handle.
 
void unreference () noexcept
 Unreference the given handle.
 
bool referenced () const noexcept
 Checks if the given handle referenced.
 
std::size_t size () const noexcept
 Returns the size of the underlying handle type.
 
int send_buffer_size ()
 Gets the size of the send buffer used for the socket.
 
int send_buffer_size (int value)
 Sets the size of the send buffer used for the socket.
 
int recv_buffer_size ()
 Gets the size of the receive buffer used for the socket.
 
int recv_buffer_size (int value)
 Sets the size of the receive buffer used for the socket.
 
os_file_descriptor fd () const
 Gets the platform dependent file descriptor equivalent.
 
- Public Member Functions inherited from uvw::resource< T, U, E >
template<typename R = void>
std::shared_ptr< R > data () const
 Gets user-defined data. uvw won't use this field in any case.
 
void data (std::shared_ptr< void > udata)
 Sets arbitrary data. uvw won't use this field in any case.
 
- Public Member Functions inherited from uvw::uv_type< U >
virtual int init ()
 Initializes the handle.
 
loopparent () const noexcept
 Gets the loop from which the resource was originated.
 
const U * raw () const noexcept
 Gets the underlying raw data structure.
 
U * raw () noexcept
 Gets the underlying raw data structure.
 
- Public Member Functions inherited from uvw::emitter< T, E... >
void on (listener_t< U > f)
 Registers a long-lived listener with the event emitter.
 
void reset () noexcept
 Disconnects the listener for the given event type.
 
void reset () noexcept
 Disconnects all listeners.
 
bool has () const noexcept
 Checks if there is a listener registered for the specific event.
 

Detailed Description

The timer handle.

Timer handles are used to schedule events to be emitted in the future.

To create a timer_handle through a loop, no arguments are required.

Definition at line 22 of file timer.h.

Member Function Documentation

◆ again()

int uvw::timer_handle::again ( )

Stops the timer and restarts it if it was repeating.

Stop the timer, and if it is repeating restart it using the repeat value as the timeout.

Returns
Underlying return value.

◆ due_in()

time uvw::timer_handle::due_in ( )

Gets the timer due value.

The time is relative to loop::now().

Returns
The timer due value or 0 if it has expired.

◆ init()

int uvw::timer_handle::init ( )
finalvirtual

Initializes the handle.

Returns
Underlying return value.

Reimplemented from uvw::uv_type< U >.

◆ repeat() [1/2]

time uvw::timer_handle::repeat ( )

Gets the timer repeat value.

Returns
Timer repeat value in milliseconds (as a std::chrono::duration<uint64_t, std::milli>).

◆ repeat() [2/2]

void uvw::timer_handle::repeat ( time  repeat)

Sets the repeat interval value.

The timer will be scheduled to run on the given interval and will follow normal timer semantics in the case of a time-slice overrun.
For example, if a 50ms repeating timer first runs for 17ms, it will be scheduled to run again 33ms later. If other tasks consume more than the 33ms following the first timer event, then another event will be emitted as soon as possible.

If the repeat value is set from a listener bound to an event, it does not immediately take effect. If the timer was non-repeating before, it will have been stopped. If it was repeating, then the old repeat value will have been used to schedule the next timeout.

Parameters
repeatRepeat interval in milliseconds (use std::chrono::duration<uint64_t, std::milli>).

◆ start()

int uvw::timer_handle::start ( time  timeout,
time  repeat 
)

Starts the timer.

If timeout is zero, a timer event is emitted on the next event loop iteration. If repeat is non-zero, a timer event is emitted first after timeout milliseconds and then repeatedly after repeat milliseconds.

Parameters
timeoutMilliseconds before to emit an event (use std::chrono::duration<uint64_t, std::milli>).
repeatMilliseconds between successive events (use std::chrono::duration<uint64_t, std::milli>).
Returns
Underlying return value.

◆ stop()

int uvw::timer_handle::stop ( )

Stops the handle.

Returns
Underlying return value.

The documentation for this class was generated from the following file: