Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create async loops #2

Closed
adrai opened this issue Jul 22, 2013 · 2 comments
Closed

create async loops #2

adrai opened this issue Jul 22, 2013 · 2 comments

Comments

@adrai
Copy link

adrai commented Jul 22, 2013

I want to execute the NanAsyncWorker again after HandleOKCallback, to do a async loop.
For example to read from a device ;-)

How would you recommend to do that? Sorry I'm not really good in C++... :-(

PS. thanks for nan, it's cool...

@rvagg
Copy link
Member

rvagg commented Jul 23, 2013

So, the worker is deleted as a result of uv_queue_work coming back, in the NanAsyncExecuteComplete function. What you could do is not use NanAsyncExecuteWorker() but call uv_queue_work() directly yourself to re-queue your worker and ensure it's not deleted and the callback handle disposed. It shouldn't be too hard: https://github.com/rvagg/nan/blob/da843e30c8197a9c9c9927b510f3ca2da7b29172/nan.h#L335

But, you might want to reconsider what you're doing, perhaps you want your JS code to be triggering the re-runs rather than having the C++ side dictating when the loops occur. Another alternative is to use polling, if you dare and have some kind of socket to react to, like the zmq module does: https://github.com/JustinTulloss/zeromq.node/blob/master/binding.cc#L355 (and I do this in node-libssh too but it's much cleaner in the zmmq one).

@rvagg rvagg closed this as completed Jul 23, 2013
@adrai
Copy link
Author

adrai commented Jul 23, 2013

agnat pushed a commit that referenced this issue May 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants