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

Async handle. More...

#include "handle-misc.hpp"

Inheritance diagram for uv::async:
uv::handle

Public Types

using uv_t = ::uv_async_t
 
using on_send_t = std::function< void(async _handle) >
 The function type of the callback called on the event raised by async::send() function. More...
 
- 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

 async (const async &)=default
 
asyncoperator= (const async &)=default
 
 async (async &&) noexcept=default
 
asyncoperator= (async &&) noexcept=default
 
 async (uv::loop &_loop)
 Create an async handle. More...
 
on_send_ton_send () const noexcept
 Set the async event callback.
 
int send () const
 Wakeup the event loop and call the async callback. 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_send_t >::value >>
int send (_Cb_ &&_cb, _Args_ &&... _args) const
 Set the given async callback and send wakeup event to the target loop. More...
 
 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

Async handle.

See also
libuv API documentation: uv_async_t — Async handle.

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

Member Typedef Documentation

◆ on_send_t

using uv::async::on_send_t = std::function< void(async _handle) >

The function type of the callback called on the event raised by async::send() function.

Note
The async event is not a facility for executing the given callback function on the target loop on every async::send() call.
See also
libuv API documentation: uv_async_cb, uv_async_send().

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

Constructor & Destructor Documentation

◆ async()

uv::async::async ( uv::loop _loop)
inlineexplicit

Create an async handle.

See also
libuv API documentation: uv_async_init().

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

Member Function Documentation

◆ send() [1/2]

int uv::async::send ( ) const
inline

Wakeup the event loop and call the async callback.

See also
libuv API documentation: uv_async_send().

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

◆ send() [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_send_t >::value >>
int uv::async::send ( _Cb_ &&  _cb,
_Args_ &&...  _args 
) const
inline

Set the given async callback and send wakeup event to the target loop.

This is equivalent for

async.on_send() = std::bind(std::forward< _Cb_ >(_cb), std::placeholders::_1, std::forward< _Args_ >(_args)...);
async.send();
See also
async::send()

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


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