Ask a question, how to post a task to main thread in node.Please my codes.
void RcibHelper::PrintLogs(const std::string & info, async_req * req){
if (fp_){
std::string content = info + "\n";
fputs(content.c_str(), fp_);
}
//TODO use direct way
uv_queue_work(uv_default_loop(),
&req->req,
DoNopAsync,
(uv_after_work_cb)AfterAsync);
}
PrintLogs runs in a new thread that created when my c++ module required. But uv_queue_work actually only can be invoked on the main thread.
Is there a way to do same thing safely?
nodejs/help may be a better place for this, but if you want to schedule code on the main thread to be run from another thread, uv_async_t may be what you are looking for.
And by the way, you can wrap pieces of source code that you post on github in ````` so that it becomes more readable, for example:
``````
printf("Hello, World!\n");
``````
becomes
printf("Hello, World!\n");
:smile:
Please don't post issues on both the node and the libuv bug tracker.
I have resolved the problem. Thanks for giving your idea.
my codes in
https://github.com/classfellow/rcib