uvcc
libuv C++ bindings
uv::work< _Result_ > Class Template Reference

Work scheduling request type. More...

#include "request-misc.hpp"

Inheritance diagram for uv::work< _Result_ >:
uv::request

Public Types

using uv_t = ::uv_work_t
 
using on_request_t = std::function< void(work _request) >
 The function type of the callback called after the work on the threadpool has been completed. More...
 
template<typename... _Args_>
using on_work_t = std::function< _Result_(_Args_ &&... _args) >
 The function type of the task which is scheduled to be run on the thread pool. More...
 
- Public Types inherited from uv::request
using uv_t = ::uv_req_t
 
using on_destroy_t = std::function< void(void *_data) >
 The function type of the callback called when the request object is about to be destroyed.
 

Public Member Functions

 work (const work &)=default
 
workoperator= (const work &)=default
 
 work (work &&) noexcept=default
 
workoperator= (work &&) noexcept=default
 
on_request_ton_request () const noexcept
 
uv::loop loop () const noexcept
 The libuv loop that started this work request and where completion will be reported. More...
 
std::shared_future< _Result_ > & result () const
 Get the result of the work.
 
template<class _Task_ , typename... _Args_, typename = std::enable_if_t< std::is_convertible< _Task_, on_work_t< _Args_&&... > >::value >>
int run (uv::loop &_loop, _Task_ &&_task, _Args_ &&... _args)
 Run the request. Queue the _Task_ to the thread pool. More...
 
 operator const uv_t * () const noexcept
 
 operator uv_t * () noexcept
 
- Public Member Functions inherited from uv::request
 request (const request &_that)
 
requestoperator= (const request &_that)
 
 request (request &&_that) noexcept
 
requestoperator= (request &&_that) noexcept
 
void swap (request &_that) noexcept
 
std::uintptr_t id () const noexcept
 
long nrefs () const noexcept
 The current number of existing references to the same object as this request variable refers to.
 
int uv_status () const noexcept
 The status value returned by the last executed libuv API function on this request.
 
on_destroy_ton_destroy () const noexcept
 
::uv_req_type type () const noexcept
 The tag indicating a libuv type of the request. More...
 
const char * type_name () const noexcept
 A string containing the name of the request type.
 
void *const & data () const noexcept
 The pointer to the user-defined arbitrary data. libuv and uvcc does not use this field.
 
void *& data () noexcept
 
int cancel () noexcept
 Cancel a pending request. More...
 
 operator const uv_t * () const noexcept
 
 operator uv_t * () noexcept
 
 operator bool () const noexcept
 Equivalent to (uv_status() >= 0).
 

Detailed Description

template<typename _Result_ = void>
class uv::work< _Result_ >

Work scheduling request type.

See also
libuv API documentation: Thread pool work scheduling.

Definition at line 23 of file request-misc.hpp.

Member Typedef Documentation

◆ on_request_t

template<typename _Result_ = void>
using uv::work< _Result_ >::on_request_t = std::function< void(work _request) >

The function type of the callback called after the work on the threadpool has been completed.

This callback is called on the loop thread.

See also
libuv API documentation: uv_after_work_cb.

Definition at line 34 of file request-misc.hpp.

◆ on_work_t

template<typename _Result_ = void>
template<typename... _Args_>
using uv::work< _Result_ >::on_work_t = std::function< _Result_(_Args_&&... _args) >

The function type of the task which is scheduled to be run on the thread pool.

This function is called on the one of the threads from the thread pool.

See also
libuv API documentation: uv_work_cb.

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

Member Function Documentation

◆ loop()

template<typename _Result_ = void>
uv::loop uv::work< _Result_ >::loop ( ) const
inlinenoexcept

The libuv loop that started this work request and where completion will be reported.

It is guaranteed that it will be a valid instance at least within the request callback.

Definition at line 84 of file request-misc.hpp.

◆ run()

template<typename _Result_ = void>
template<class _Task_ , typename... _Args_, typename = std::enable_if_t< std::is_convertible< _Task_, on_work_t< _Args_&&... > >::value >>
int uv::work< _Result_ >::run ( uv::loop _loop,
_Task_ &&  _task,
_Args_ &&...  _args 
)
inline

Run the request. Queue the _Task_ to the thread pool.

The given _Task_ function is called with specified _args applied and is executed on the one of the threads from the thread pool. Once it is completed, on_request callback will be called on the _loop thread.

Note
All arguments are copied (or moved) to the _task function object. For passing arguments by reference (when parameters are used as output ones), wrap them with std::ref() or use raw pointers.
See also
libuv API documentation: uv_queue_work().

Definition at line 99 of file request-misc.hpp.


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