老大前几天提到libuv,我只看过一点libevent, 听说过libev,没听说过libuv,查了一下才知道libuv。
先到github git clone 源码,编译,测试,看测试代码
头文件uv.h定时器部分的函数,头文件有详细的注释
* uv_timer_t is a subclass of uv_handle_t.
*
* Used to get woken up at a specified time in the future.
*/
struct uv_timer_s {
UV_HANDLE_FIELDS
UV_TIMER_PRIVATE_FIELDS
};
UV_EXTERN int uv_timer_init(uv_loop_t*, uv_timer_t* handle);
/*
* Start the timer. `timeout` and `repeat` are in milliseconds.
*
* If timeout is zero, the callback fires on the next tick of the event loop.
*
* If repeat is non-zero, the callback fires first after timeout milliseconds
* and then repeatedly after repeat milliseconds.
*/
UV_EXTERN int uv_timer_start(uv_timer_t* handle,
&nb

本文介绍了libuv库中的定时器功能,通过查看源码、编译和测试来学习如何使用libuv定时器。文章展示了初始化、设置回调函数和运行的主要步骤,并提醒了uv_timer_start中repeat参数影响回调的重复执行。通过提供的测试代码,读者可以掌握libuv定时器的基本用法。
最低0.47元/天 解锁文章
360

被折叠的 条评论
为什么被折叠?



