-
Notifications
You must be signed in to change notification settings - Fork 9
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
Review #126
Comments
Apologies for bringing this up again, as I think we discussed it previously but I can't find where, but what does the following mean in
Unique per-driver instance or per-process? |
Unique to the driver, but I guess we need to add that to the docblock. |
Okay. Now that |
@joshdifabio basically: public static function getNewIdentifier() {
static $i = "a";
return $i++;
} I do not object per se, but perhaps for some reason implementations may want to use resource ids or object hashes as watcher id … It'd save them an extra mapping. Thus there may be some advantage in giving implementations freedom over their ids. |
Thanks @bwoebi. My idea is similar but includes a driver identifier to highlight situations where the application is attempting to reference a watcher from a different driver instance.
If watcher ID's must be unique per-driver instance then I guess that rules out object hashes?
Sure, I accept that this might be the case. I'll make a quick PR this evening and then perhaps you guys who are responsible for implementing loops can comment. I'm open to the possibility that it might be the wrong approach. |
Ah right. @joshdifabio Please PR it then, I'll probably approve it. |
Cheers. I'll do so after work this evening. |
Hi guys, I'm also trying to review the code and documentation. So far I've analyze the code and I'm going to look for implementations and usage examples to be sure I understand the intent. My first question is related to the usability of the loop registry. |
@bwoebi wanted to provide a PR explaining all the things in a META document. @drealecs You can see an actual use case here: https://github.com/amphp/dns/blob/badf3a91003814ce574030a3d695978099d15301/lib/functions.php#L16-L25 Basically everything that's static and needs the loop should use something stored to the loop state. |
Thank you, I understood why it is needed. I believe there might be other ways to do this, not necessary having a registry implemented in the loop. |
Note that in case we shift that responsibility onto the respective classes (e.g. the DNS drivers), it does not know when a loop has been freed and will reference the state forever, even though the particular loop instance has been long abandoned. … That's what one calls a memory leak and must be avoided. |
Indeed, I thought about it more and seems simpler and safer this way. |
As a different topic, I saw some discussion about how a loop should work. As I'm not actively using an async library at this time, I tend to care more about what form should be used to better cover all aspects. I was thinking that you could even have something like this in 'index.php' Loop::execute(function(){require('index-async.php');}); And with this, I got to an idea that maybe some of you have already though about it and can come up with an answer why it would work or not: Add event loop in the PHP runtime directly, as a PHP extension Namespaced functions for adding watchers and controlling them will be available. I don't have a very in detail knowledge about what a PHP extension can do but having something like that would be a lot better for usability and future interoperability. |
Yes, we already thought about that, but not in public yet. But it'd probably be much more like https://github.com/php-ds with this package here being the polyfill and the extension replacing the polyfill if available. The issue with your approach is that it requires the extension then, it's not polyfillable in userland. And if there's only one truly global loop, how do we test then? Require everything in every test to clean up each and every watcher? Test with a new process for each test case? The main point for having an extension would be the possibility of writing other extensions directly integrating with the loop. |
I wasn't thinking that we need to be able to provide a polyfill for the extension; maybe there is no need to. Maybe a way would be to have this in the beggining of a file: <?php
require_once 'vendor/autoload.php';
if (!\EventLoop\isRunning()) {
return \EventLoop\runStartingWithFile(__FILE__);
}
//... continue with the execution Related to testing, I would ask "how do you test an async javascript functionality?" |
Requiring an extension to be installed greatly hinders adoption. If you read https://www.martinfowler.com/articles/asyncJS.html, you'll see that it mostly just advises not to test async code, but mock all async components in a sync way. https://www.martinfowler.com/articles/nonDeterminism.html is the more important one, talking about isolation of test cases. It's not a good idea to require test cases to clean everything up. All other tests shouldn't be affected either way. You might also want to have a look at https://github.com/nodejs/node/blob/master/doc/guides/writing-tests.md, which uses one process per test, like PHPT tests do. Generally, you want to have a look at how Node tests are written, not client side JS tests, because client side JS really usually can avoid async APIs. Now you might say we can also use PHPUnit's |
Could you please all review the full specification including all documents and documentation comments and post a comment afterwards here? Please review carefully and don't just put your thumb up here.
@trowski @assertchris @AndrewCarterUK @bwoebi @WyriHaximus @rdlowrey @sagebind @jsor
The text was updated successfully, but these errors were encountered: