Created
March 16, 2013 21:45
-
-
Save bionicbeagle/5178463 to your computer and use it in GitHub Desktop.
Example of using libuv with stateless lambdas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize uv_async_t for shutting down event loop | |
m_shutdownAsync.data = this; | |
uv_async_init(m_eventLoop, &m_shutdownAsync, [](uv_async_t* handle, int status) { | |
auto thisPtr = reinterpret_cast<DiscoService*>(handle->data); | |
uv_close((uv_handle_t*) handle, nullptr); | |
uv_close((uv_handle_t*) &thisPtr->m_recvSocket, nullptr); | |
uv_close((uv_handle_t*) &thisPtr->m_sendSocket, nullptr); | |
uv_close((uv_handle_t*) &thisPtr->m_timer, nullptr); | |
uv_close((uv_handle_t*) &thisPtr->m_heartbeat, nullptr); | |
}); | |
// Start a repeating timer | |
m_timer.data = this; | |
uv_timer_init(m_eventLoop, &m_timer); | |
uv_timer_start(&m_timer, [](uv_timer_t* handle, int status) { | |
auto thisPtr = reinterpret_cast<DiscoService*>(handle->data); | |
printf("tick\n"); | |
}, 1000, 30000); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment