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

Comments

@adrai
Copy link

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

This comment has been minimized.

Copy link
Member

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 Jul 23, 2013
@adrai

This comment has been minimized.

Copy link
Author

commented Jul 23, 2013

agnat pushed a commit that referenced this issue May 6, 2019
Update asyncworker.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.