如何保持节点uv_run退出当主持自己的线程添加?
我有一个自定义的服务器运行在自己的POSIX线程本地节点添加。
保持节点进程运行uv_run事件循环的正确方法是什么? 换句话说,如果我通过脚本在“添加”中启动服务器,则我的过程将在脚本结束时退出,而不是保持事件循环运行。
我已经尝试通过process.on添加SignalWatcher,并且仍然退出。 我没有看到过程对象中的任何其他东西从脚本做到这一点。
在node.cc中,有这样的评论:
// Create all the objects, load modules, do everything. // so your next reading stop should be node::Load()! Load(process_l); // All our arguments are loaded. We've evaluated all of the scripts. We // might even have created TCP servers. Now we enter the main eventloop. If // there are no watchers on the loop (except for the ones that were // uv_unref'd) then this function exits. As long as there are active // watchers, it blocks. uv_run(uv_default_loop()); EmitExit(process_l);
Add On必须做什么?
我已经尝试在启动服务器/ pthread的时候在我的Add On主线程中调用uv_ref(uv_default_loop()),但是进程仍然退出。
注:我可以绑定到TCP / UDP端口或设置一个计时器,这将保持uv_run退出,但我想这样做是“正确”的方式。