[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.
|
|
||
| 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.
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