[WIP][3.x] Add Io\Poll Event Loop - #286
WyriHaximus wants to merge 1 commit into
Conversation
| break; | ||
| } | ||
|
|
||
| foreach ($this->context->wait(\Time\Duration::fromMicroseconds((float) $timeout)) as $watcher) { |
There was a problem hiding this comment.
fromMicroseconds() doesn't take a float. This cast looks fishy (particularly since you will also cast $timout = null.
There was a problem hiding this comment.
Was running beta3 locally, I guess that changed in RC1? As it threw errors at me when passing it an int.
There was a problem hiding this comment.
No, the implementation is effectively unchanged since it initially landed: https://github.com/php/php-src/commits/master/ext/date/time_duration.c.
int is definitely what is expected: https://github.com/php/php-src/blob/3d979856590e19ac533e29c21d634c991ac6e9f8/ext/date/time.stub.php#L36-L38 / https://github.com/php/php-src/blob/3d979856590e19ac533e29c21d634c991ac6e9f8/ext/date/time_duration.c#L247
There was a problem hiding this comment.
And generally speaking, you likely want the Duration::fromSeconds() constructor here. Something like:
$seconds = (int)$float;
$nanoseconds = (int)(($float - $seconds) * 1_000_000_000);
Duration::fromSeconds($seconds, $nanoseconds);
should hopefully work.
There was a problem hiding this comment.
Found that I was an idiot, on line 156 $timeout is assigned null and in my hasty reading I mixed that with int. It's working fine now.
There was a problem hiding this comment.
Found that I was an idiot, on line 156
$timeoutis assignednull
Was null = infinite the desired timeout or was this a typo and it should indeed be a zero timeout as it is now?
|
|
||
| foreach ($this->context->wait(\Time\Duration::fromMicroseconds((float) $timeout)) as $watcher) { | ||
| $stream = $watcher->getHandle()->getStream(); | ||
| $key = (int) $stream; |
There was a problem hiding this comment.
You can probably use the associated getData() of a watcher to reference the application state to avoid this cast.
There was a problem hiding this comment.
Hoping to, noticed it when getting the first working run. This is pretty much a copy of the stream_select() event loop, so it also does things in mostly the same way. Exploring getData() next and other ways of utilizing everything that comes with this. Really liking the Time\Duration to pass the wait in.
P.S. Thanks for the early feedback <3
There was a problem hiding this comment.
Really liking the
Time\Durationto pass the wait in.
Appreciated. I really wanted to get Time\Duration into PHP 8.6 last minute so that the polling API doesn't start right of with a “meh” API.
There was a problem hiding this comment.
Really liking the
Time\Durationto pass the wait in.Appreciated. I really wanted to get Time\Duration into PHP 8.6 last minute so that the polling API doesn't start right of with a “meh” API.
Aye, this is way cleaner. @clue was enthusiastically surprised when I mentioned the addition of Time\Duration. Also, the public readability of its properties is :chefskiss: .
Also started using Watchet::getData() to pass the key arround, not sure if it's the cleanest solution. But will revisit that once I verfied a fully functional event loop.
There was a problem hiding this comment.
Also started using
Watchet::getData()to pass the key arround, not sure if it's the cleanest solution.
If possible with the architecture you probably want to store an object with properties for the read- and write callback as the data to avoid managing multiple arrays.
054ec29 to
e80bd13
Compare
e80bd13 to
eed4d36
Compare
This PR is a work in progress. This is a first PoC, no tests have been ran, only two examples tested. Will be updated as documentation etc is added