-
Notifications
You must be signed in to change notification settings - Fork 38
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
Recoil asynchronous framework #70
Comments
I've struggled to explain this well, I'll do my best :) I should start by saying two things:
What Recoil tries to do is to make writing asynchronous code "feel" like synchronous code. If you're familiar with asynchronous IO and/or apps based on the reactor pattern (be it via React, NodeJS, boost::asio, whatever), you'll also be familiar with passing callbacks around to receive results from asynchronous operations, this often means not being able to use return values and having to explicitly check for error conditions, etc. Recoil uses PHP generators, specifically their ability to suspend and resume execution as the 'break points' where code can wait for asynchronous events to occur, rather than having to provide a callback. This example, which uses Recoil to asynchronously/concurrently resolve some domain names can be compared to this one, which is equivalent but uses React DNS and promises directly. Note specifically the control flow and the way in which errors are reported. I like to think that (except for the Hopefully these examples help make some sense of the idea behind Recoil. It's by no means original, but I think Recoil is the first 'full featured' implementation for PHP... whatever that might mean :) If you've got the time, this article by @nikic is an excellent walkthrough of a system with the same underlying idea as Recoil. Of course, please feel free to ask further questions right here. |
I just read through the long article by Nikic. I'll need to look into it deeper later. But some questions came to mind:
The only thing stopping me from fully committing to async frameworks is usually the ecosystem of tools that PHP built up are by majority not asynchronous. There's yet to be an ORM like Doctrine or Propel that's asynchronous. Hopefully this could help. Just in the question of reactor patterns in general. It seems most reactor patterns are single threaded, are there implementations which try to do reactor patterns that are inherently multithreaded? |
You're absolutely right about the fact that the majority of tools for PHP are not asynchronous, furthermore, even if they were they need to target the same reactor implementation (eg, React) to be used together. For what it's worth, I'm trying to get an asynchronous PDO-like abstraction happening here. It's not 100% complete, but it works and could serve as a basis for an ORM implementation in the asynchronous world. I think I will probably change this library to be written using promises so that it can work directly with React. The only reactor implementation I know of that has explicit support for threads is Boost.Asio for C++, see here and here, note also that what Asio refers to as 'strands' is somewhat different to a 'strand' in Recoil. |
One thing to note with regards to multithreading. Is that coroutines will always be bound to 1 logical cpu core. So you can't take advantage of true parrallelism. |
Possibly relevant to your interests : https://gist.github.com/krakjoe/6437782/ |
Yep I know about that and have considered pthreads. However the problem is that it relies on a specific compiled version of PHP. |
Have you seen swoole https://github.com/matyhtf/swoole It looks very interesting. Perhaps recoil could be integrated in Swoole? |
What's the difference between using ReactPHP by itself and using Recoil? If I was building a new asynchronous application, would I put Recoil on top of ReactPHP? What kind of advantages does it provide?
The text was updated successfully, but these errors were encountered: