Skip to content

[RFC] Singularity #10

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

Closed
wants to merge 1 commit into from
Closed

[RFC] Singularity #10

wants to merge 1 commit into from

Conversation

igorw
Copy link
Contributor

@igorw igorw commented Aug 17, 2014

This pull request serves as a place for discussing some radical changes to the react API that I've been playing with. This is just a concept. It's just an idea. It needs a lot more work before the rest of react could use it.

Feel free to share your thoughts here though.

…e APIs in the future

Let's face it. There can only be one loop. If we accept this simple fact, we can build
much nicer APIs that no longer have to awkwardly pass this loop object around that already
is a semi-global context object leaking all over the system.
@WyriHaximus
Copy link
Member

This is honestly one of the few moments I really like the idea of some global state. Without even going deed into the code it will make writing react applications considerable simpler as we don't have to pass the loop around anymore (there can only be ONE anyway). I'm really in favor of the PR 👍 !

@cboden cboden added this to the v0.5 milestone Aug 17, 2014
@steverhoades
Copy link
Contributor

If the idea here is that I can do:

$stream   = new Stream($fd);

instead of

$stream   = new Stream($fd, $loop);

I'm +1000 for this. Passing the event loop around is a real PITA.

@igorw
Copy link
Contributor Author

igorw commented Aug 23, 2014

I was aiming for something like:

react\fread($fd, 1024)->then(function ($data) { ... });

@@ -59,11 +52,11 @@ public function isPeriodic()

public function isActive()
{
return $this->loop->isTimerActive($this);
return l\loop()->isTimerActive($this);
Copy link
Member

Choose a reason for hiding this comment

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

IMHO it makes sense to no longer expose the loop as part of the timer interface (i.e. drop the getLoop() method).

Though arguably, I'm also pro exposing the one loop via global state.

However, I consider this very change a design flaw. Unless we move this logic to the timer itself, it actually does have a dependency on the loop. Accessing global state here means we're using a leaky abstraction and hiding the dependencies this particular class has. Also, this does make testing harder (no built-in mechanism to mock the loop).

@clue
Copy link
Member

clue commented Jun 6, 2015

I agree, this appears to one of the few places where it actually makes sense to add global state. If only for convenience (and hence a cleaner design for components building on top of this) 👍

I've toyed with the concept of combing several loops for some time already, but even then there's only ever a single "top" loop.

So while I agree it makes sense to add a global accessor (let's face it, we're talking about a beloved singleton), I tend to disagree with actually using it in any of our methods (except for constructors).

@mbonneau
Copy link

mbonneau commented Nov 6, 2015

👍 - Would also like to see the loop start automatically.


class Factory
{
public static function create()
Copy link

Choose a reason for hiding this comment

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

Could this stay and just return loop(); ?

@mbonneau
Copy link

mbonneau commented Feb 3, 2016

This PR has been here for well over a year. Anyone who would like to comment has had the opportunity. Can we get a yes or no on this?

@clue clue removed the api change label Nov 17, 2016
@clue clue removed this from the v0.5.0 milestone Feb 8, 2017
@clue clue changed the title Singularity [RFC] Singularity Feb 8, 2017
@jsor jsor mentioned this pull request Feb 11, 2017
@mdrost
Copy link

mdrost commented May 15, 2017

Is there any case when having two loops is helpful?

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.

7 participants