Node: Ask a question, how to post a task to main thread in node.Please see my codes.

Created on 30 Jun 2016  路  4Comments  路  Source: nodejs/node

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?

invalid libuv question

All 4 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

loretoparisi picture loretoparisi  路  3Comments

ksushilmaurya picture ksushilmaurya  路  3Comments

fanjunzhi picture fanjunzhi  路  3Comments

addaleax picture addaleax  路  3Comments

filipesilvaa picture filipesilvaa  路  3Comments