Skip to content
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

Add static Loop methods #229

Merged
merged 1 commit into from
Jun 30, 2021
Merged

Conversation

clue
Copy link
Member

@clue clue commented Jun 29, 2021

This changeset adds static Loop methods. The Loop class now provides all methods that exist on the LoopInterface as static methods:

use React\EventLoop\Loop;

// old (still supported)
Loop::get()->addTimer(1.0, fn () => echo 'Tick');
Loop::get()->run();

// new
Loop::addTimer(1.0, fn () => echo 'Tick');
Loop::run();

This is particularly useful when directly interfacing with the event loop in application code. I've also updated the documentation to highlight some use cases where the Loop::get() method would still be useful when using dependency injection (DI).

Builds on top of #226

@clue clue added this to the v1.2.0 milestone Jun 29, 2021
@@ -47,4 +47,154 @@ public static function set(LoopInterface $loop)
{
self::$instance = $loop;
}

/**
* [Advanced] Register a listener to be notified when a stream is ready to read.
Copy link
Member

Choose a reason for hiding this comment

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

Why are only adding streams marked as advanced? IMHO if we mark those two we should also mark removeReadStream && removeWriteStream as such. And maybe mention react/stream for easier usage.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair point. I've applied the exact same documentation from the LoopInterface::addReadStream() method:

* [Advanced] Register a listener to be notified when a stream is ready to read.

Your suggestion sounds perfectly reasonable, perhaps file this as a follow-up PR to also adjust the interface and the README (similar to #110)? 👍

Copy link
Member

Choose a reason for hiding this comment

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

Will do 👍

@clue
Copy link
Member Author

clue commented Jun 29, 2021

Rebased on master now that #230 is in to trigger a new test run :shipit:

@clue
Copy link
Member Author

clue commented Jun 30, 2021

Updated to move deprecation notices out of this PR and split this up into a dedicated PR #231. To ease review, this PR here now only deals with the new static methods.

(Merging either PR will likely cause a merge conflict with the other PR, but I'd rather put the burden of rebasing and fixing this conflict onto myself than the people reviewing this.)

@WyriHaximus WyriHaximus merged commit a499b82 into reactphp:master Jun 30, 2021
@clue clue deleted the loop-methods branch July 16, 2021 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants