/
async.h
58 lines (48 loc) · 1.27 KB
/
async.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef UVW_ASYNC_INCLUDE_H
#define UVW_ASYNC_INCLUDE_H
#include <uv.h>
#include "handle.hpp"
#include "loop.h"
namespace uvw {
/*! @brief Async event. */
struct async_event {};
/**
* @brief The async handle.
*
* Async handles allow the user to _wakeup_ the event loop and get an event
* emitted from another thread.
*
* To create an `async_handle` through a `loop`, no arguments are required.
*/
class async_handle final: public handle<async_handle, uv_async_t, async_event> {
static void send_callback(uv_async_t *hndl);
public:
using handle::handle;
/**
* @brief Initializes the handle.
*
* Unlike other handle initialization functions, it immediately starts the
* handle.
*
* @return Underlying return value.
*/
int init();
/**
* @brief Wakeups the event loop and emits the async event.
*
* It’s safe to call this function from any thread.<br/>
* An async event is emitted on the loop thread.
*
* See the official
* [documentation](http://docs.libuv.org/en/v1.x/async.html#c.uv_async_send)
* for further details.
*
* @return Underlying return value.
*/
int send();
};
} // namespace uvw
#ifndef UVW_AS_LIB
# include "async.cpp"
#endif
#endif // UVW_ASYNC_INCLUDE_H