uvcc
libuv C++ bindings
uv::timer Class Reference

Timer handle. More...

#include "handle-misc.hpp"

Inheritance diagram for uv::timer:
uv::handle

Public Types

using uv_t = ::uv_timer_t
 
using on_timer_t = std::function< void(timer _handle) >
 The function type of the callback called by the timer event.
 
- Public Types inherited from uv::handle
using uv_t = ::uv_handle_t
 
using on_destroy_t = std::function< void(void *_data) >
 The function type of the callback called when the handle has been closed and about to be destroyed. More...
 

Public Member Functions

 timer (const timer &)=default
 
timeroperator= (const timer &)=default
 
 timer (timer &&) noexcept=default
 
timeroperator= (timer &&) noexcept=default
 
 timer (uv::loop &_loop, uint64_t _repeat_interval=0)
 Create a timer handle which has a given repeat interval. More...
 
uint64_t repeat_interval () const noexcept
 Get the timer repeat interval in milliseconds.
 
void repeat_interval (uint64_t _value) noexcept
 Set the timer repeat interval in milliseconds. More...
 
on_timer_ton_timer () const noexcept
 Set the timer callback.
 
int start (uint64_t _timeout) const
 Start the timer by scheduling a timer event after the _timeout interval expires. More...
 
template<class _Cb_ , typename... _Args_, typename = std::enable_if_t< std::is_convertible< decltype(std::bind(std::declval< _Cb_ >(), std::placeholders::_1, static_cast< _Args_&& >(std::declval< _Args_ >())...)), on_timer_t >::value >>
int start (uint64_t _timeout, _Cb_ &&_cb, _Args_ &&... _args) const
 Start the timer with the given callback. More...
 
int stop () const noexcept
 Stop the timer, the callback will not be called anymore.
 
 operator const uv_t * () const noexcept
 
 operator uv_t * () noexcept
 
- Public Member Functions inherited from uv::handle
 handle (const handle &_that)
 
handleoperator= (const handle &_that)
 
 handle (handle &&_that) noexcept
 
handleoperator= (handle &&_that) noexcept
 
void swap (handle &_that) noexcept
 
std::uintptr_t id () const noexcept
 The unique ID of the instance managed by this handle variable or 0 if the handle is void.
 
long nrefs () const noexcept
 The current number of existing references to the same object as this handle variable refers to.
 
int uv_status () const noexcept
 The status value returned by the last executed libuv API function on this handle.
 
on_destroy_ton_destroy () const noexcept
 
::uv_handle_type type () const noexcept
 The tag indicating the libuv type of the handle.
 
const char * type_name () const noexcept
 A string containing the name of the handle type.
 
uv::loop loop () const noexcept
 The libuv loop where the handle is running on. More...
 
void *& data () const noexcept
 The pointer to the user-defined arbitrary data. libuv and uvcc does not use this field.
 
int is_active () const noexcept
 Check if the handle is active. More...
 
int is_closing () const noexcept
 Check if the handle is closing or closed. More...
 
::uv_os_fd_t fileno () const noexcept
 Get the platform dependent handle/file descriptor. More...
 
 operator const uv_t * () const noexcept
 
 operator uv_t * () noexcept
 
 operator bool () const noexcept
 Equivalent to (id() and uv_status() >= 0).
 
void attached (bool _state) const noexcept
 
bool attached () const noexcept
 

Detailed Description

Timer handle.

See also
libuv API documentation: uv_timer_t — Timer handle.

Definition at line 154 of file handle-misc.hpp.

Constructor & Destructor Documentation

◆ timer()

uv::timer::timer ( uv::loop _loop,
uint64_t  _repeat_interval = 0 
)
inlineexplicit

Create a timer handle which has a given repeat interval.

_repeat_interval is in milliseconds.

Definition at line 204 of file handle-misc.hpp.

Member Function Documentation

◆ repeat_interval()

void uv::timer::repeat_interval ( uint64_t  _value)
inlinenoexcept

Set the timer repeat interval in milliseconds.

Note
Setting the repeat value to zero turns the timer to be non-repeating.
See also
uv_timer_set_repeat().

Definition at line 222 of file handle-misc.hpp.

◆ start() [1/2]

int uv::timer::start ( uint64_t  _timeout) const
inline

Start the timer by scheduling a timer event after the _timeout interval expires.

The timer callback function will be called after _timeout milliseconds or, if it is equal to 0, on the next event loop iteration and then repeatedly after each repeat_interval(), if the latter is non-zero.

Repeated call to this function results in the automatic call to stop() first.

Note
On successful start this function adds an extra reference to the handle instance, which is automatically released when the timer stops because of being non-repeating or the counterpart function stop() is called.
See also
libuv API documentation: uv_timer_start().

Definition at line 236 of file handle-misc.hpp.

◆ start() [2/2]

template<class _Cb_ , typename... _Args_, typename = std::enable_if_t< std::is_convertible< decltype(std::bind(std::declval< _Cb_ >(), std::placeholders::_1, static_cast< _Args_&& >(std::declval< _Args_ >())...)), on_timer_t >::value >>
int uv::timer::start ( uint64_t  _timeout,
_Cb_ &&  _cb,
_Args_ &&...  _args 
) const
inline

Start the timer with the given callback.

This is equivalent for

timer.on_timer() = std::bind(
std::forward< _Cb_ >(_cb), std::placeholders::_1, std::forward< _Args_ >(_args)...
);
timer.start(_timeout);
See also
timer::start()

Definition at line 276 of file handle-misc.hpp.


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