help
help copied to clipboard
uv_timer_init and uv_timer_stop
- Version: 1.34.2-1ubuntu1
- Platform: 4.19.84-microsoft-standard when uv_timer_init is called, a handle will be insert into loop->handle_queue, but how can I remove it from the loop->handle_queue after the timer is stop?
I wrote some testing code, and I got a dead loop.
#include <uv.h>
#include <iostream>
#include "queue.h"
using namespace std;
int main(int argc, char const* argv[])
{
uv_loop_t* loop = uv_default_loop();
uv_timer_t t;
uv_timer_init(loop, &t);
uv_timer_start(&t, nullptr, 1000, 1000);
uv_timer_stop(&t);
uv_close((uv_handle_t*)&t, nullptr);
cout << "init again" << endl;
uv_timer_init(loop, &t);
uv_print_all_handles(loop, stdout);
uv_timer_start(&t, nullptr, 1000, 1000);
//uv_print_all_handles(loop, stdout);
uv_timer_stop(&t);
//uv_print_all_handles(loop, stdout);
uv_close((uv_handle_t*)&t, nullptr);
//uv_print_all_handles(loop, stdout);
return 0;
}
uv_close()
will remove the timer again.
However, you're reinitializing it again immediately after calling uv_close()
. Don't do that, you need to call uv_run()
first and wait for the close callback.
I get it. Thank you very much.
发自我的iPhone
在 2020年7月21日,下午4:55,Ben Noordhuis [email protected] 写道:
uv_close() will remove the timer again.
However, you're reinitializing it again immediately after calling uv_close(). Don't do that, you need to call uv_run() first and wait for the close callback.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.