uvw  2.0.0
async.hpp
1 #pragma once
2 
3 
4 #include <utility>
5 #include <memory>
6 #include <uv.h>
7 #include "handle.hpp"
8 #include "loop.hpp"
9 
10 
11 namespace uvw {
12 
13 
19 struct AsyncEvent {};
20 
21 
30 class AsyncHandle final: public Handle<AsyncHandle, uv_async_t> {
31  static void sendCallback(uv_async_t *handle) {
32  AsyncHandle &async = *(static_cast<AsyncHandle*>(handle->data));
33  async.publish(AsyncEvent{});
34  }
35 
36 public:
37  using Handle::Handle;
38 
47  bool init() {
48  return initialize(&uv_async_init, &sendCallback);
49  }
50 
61  void send() {
62  invoke(&uv_async_send, get());
63  }
64 };
65 
66 
67 }
void send()
Wakeups the event loop and emits the AsyncEvent event.
Definition: async.hpp:61
Handle base class.
Definition: handle.hpp:29
The AsyncHandle handle.
Definition: async.hpp:30
AsyncEvent event.
Definition: async.hpp:19
bool init()
Initializes the handle.
Definition: async.hpp:47
uvw default namespace.
Definition: async.hpp:11