libuv中async的使用比较难理解一些,我们来一起学习下
简介
vu_async_t是我们要用的handle,这个handle用来在线程间通信的。我们看一下官方的解释
/*
* uv_async_t is a subclass of uv_handle_t.
*
* uv_async_send wakes up the event loop and calls the async handle's callback.
* There is no guarantee that every uv_async_send call leads to exactly one
* invocation of the callback; the only guarantee is that the callback function
* is called at least once after the call to async_send. Unlike all other
* libuv functions, uv_async_send can be called from another thread.
*/
也就是说配合 uv_async_send,可以唤醒持有async的消息队列,并调用async的回调,而且这个是跨线程的,只保证uv_async_send调用一次之后, callback也必然至少调用一次,但是因为是很多线程可以同时发送唤醒消息,所以,也可能被多次调用啦。