Skip to content

[WIP][3.x] Add Io\Poll Event Loop - #286

Draft
WyriHaximus wants to merge 1 commit into
reactphp:3.xfrom
WyriHaximus-labs:3.x-io-poll-loop
Draft

WyriHaximus wants to merge 1 commit into
reactphp:3.xfrom
WyriHaximus-labs:3.x-io-poll-loop

Conversation

@WyriHaximus

Copy link
Copy Markdown
Member

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

@WyriHaximus WyriHaximus added this to the v3.0.0 milestone Sep 25, 2026
Comment thread src/IoPollLoop.php
break;
}

foreach ($this->context->wait(\Time\Duration::fromMicroseconds((float) $timeout)) as $watcher) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fromMicroseconds() doesn't take a float. This cast looks fishy (particularly since you will also cast $timout = null.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was running beta3 locally, I guess that changed in RC1? As it threw errors at me when passing it an int.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TimWolla TimWolla Sep 25, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/IoPollLoop.php

foreach ($this->context->wait(\Time\Duration::fromMicroseconds((float) $timeout)) as $watcher) {
$stream = $watcher->getHandle()->getStream();
$key = (int) $stream;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably use the associated getData() of a watcher to reference the application state to avoid this cast.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really liking the Time\Duration to 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants