help icon indicating copy to clipboard operation
help copied to clipboard

Safe to run uv_run inside callback?

Open nickwanninger opened this issue 6 years ago • 2 comments

Hello,

I have a specific problem in a project I have that requires that the event loop be run a couple times from within a callback, and I'm not sure if the bug I'm experiencing is coming from that not being safe or somewhere else in my code. I can't seem to find any docs prohibiting this outright so I just want to make sure.

I'm basically doing a uv_run(loop, UV_RUN_ONCE); from within a callback

Thanks in advance

nickwanninger avatar Feb 25 '19 10:02 nickwanninger

I can't seem to find any docs prohibiting this outright so I just want to make sure.

I've opened a PR that adds a warning. :-)

The short answer is that you can't, uv_run() isn't reentrant. We've discussed adding that functionality in the past but the conclusion was that it was too much effort and overhead for not enough gain.

bnoordhuis avatar Feb 25 '19 11:02 bnoordhuis

Hmm okay, that would explain some of the errors I'm seeing :)

thanks for the help, seems like I may need to refactor a bit

nickwanninger avatar Feb 25 '19 12:02 nickwanninger