uv_async_send() is what you want for this case I believe, it ought to be 
able to get data back into the event loop thread from a worker thread. Just 
make sure you have a Persistent handle to the callback function so garbage 
collection doesn't get it before you've stopped using it.

Check out this (pure libuv) example to get an idea of what's going on: 
http://nikhilm.github.io/uvbook/threads.html#inter-thread-communication 
notice how there's two mechanisms for getting back in to the event loop, 
uv_queue_work comes back when the work is completed but uv_async_send is 
able to report ongoing progress before the worker is actually finished. 
Translating that example to Node, you'd have main(), print_progress() and 
after() being in the event loop thread (the V8 thread where you can mess 
with V8 objects and execute callback functions into JS-land) while 
fake_download() is in a worker thread where you shouldn't be touching V8 
objects directly.

I hope that helps (and that I've got it right, hopefully Ben will correct 
me if I've got anything wrong here).
 -- Rod


On Friday, 26 July 2013 08:05:03 UTC+10, Sánta Gergely wrote:
>
> My problem is the following: In my cpp program, there is a main loop, 
> which constantly counts 3D coordinates. And as soon as a newly counted 
> coordinate is available, I would like it (the cpp program) to notify my 
> node.js program through some event.
>
> A few days ago, someone in the mailing list gave me this link: 
> https://github.com/rvagg/node-addon-examples/tree/master/9_async_work/
>
> This is a very good starting point, becuse it tells, how to call 
> cpp asynchronously. I call the cpp function from node.js, give that 
> function my node.js callback function,
> but I can not call that callback from cpp periodically, only once. Maybe I 
> don't understand it completely, but as I could figure out, in the async.cc 
> file the CalculateAsync function hasto return, and after it returned, 
> will be my node.js callback function invoked (so I can not call it more 
> than once).
>
> Is there any chance to implement some kind of event somehow?
>
> Thanks,
> Gergo
>

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to