-
-
Notifications
You must be signed in to change notification settings - Fork 16
Allow waiting inside a loop by ticking instead of running the loop #19
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
Conversation
Thanks for your PR @JurJean! 👍 This change essentially reverts #1: Running
I'm not sure this is something we ought to support. Can you give some use cases / usage examples? |
That's sad to hear! The reason I want to do this is that I don't like everything becoming a Closure while using react, and want to create solid code where I can. The thing is, that I'm using the same loop for both serving http requests and fetching data from eventstore over tcp (just for the fun of it). The loading of events can be refactored to be asynchronous I think, but the writing cannot. I tried to create two loops but that did not work, the http loop stopped working. Maybe I need to rethink the whole thing, but still, I feel it should be possible. Here are some points of interest of the application I'm talking about: Furthermore, I can do it with Akka framework in Java. While they say it's discouraged to do, you may do so if you know you have to. |
I've created a pull request at react/event-loop that resolves the cpu usage problem calling tick() in a while loop. |
I'm not sure I follow that sentiment, as it's very well possible (and my personal aim 8000 ) to write SOLID code when using React PHP.
I think this is the real culprit here. React is built around the concept of using a single EventLoop (the reactor) that will block everything else. I'm not familiar with the domain you're in, but it usually should be possible to rewrite your "writing process" to be async. This should allow you to use a single loop and fix any problems you're seeing 👍 I hope this helps 👍 |
Thanks for your response! I'm sure stuff can be refactored into more solid code. Fact remains, that it's perfectly acceptable to wait for something to become available, without the use of a callback. In other languages its done all the time. I'm not talking about running a second event loop, I want to keep running the loop non-blocking, until some result becomes available and then continue. I really don't see what would be the problem as it's implemented with a few changes in the code. Currently using icicleio, which does support it, and its awesome. |
I'm still not sure I follow that sentiment :-) This library is here to do exactly this, it allows you to await something without using callbacks and hence has to block the loop.
React is built around the concept of using only non-blocking code or using IPC for blocking parts, but not ever mixing these two. I understand where you're coming from, as this often makes integration with existing (traditional) systems more complex and this library is here to help :-)
The suggested PR builds on the assumption that
Happy to hear you've got this sorted 👍 |
Allright then, still not convinced but I'm sure you know you're talking about :) Thanks anyway! |
I needed to wait for a promise while already within a loop. Because the await() function calls $loop->stop(), the loop I was already in stopped.
I removed $loop->stop() and instead of $loop->run() I now call $loop->tick(). This has resolved my problem. The unittests are still working as well.
Please let me know about any problems with this approach, I will try to resolve them.