Skip to content

Resolve #142 by adding a run() method #145

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 2 commits into from
Closed

Conversation

bwoebi
Copy link
Member

@bwoebi bwoebi commented Jan 29, 2017

As per: #142 (comment)

Also adding a shutdown function at the end in order to ensure that the loop level will be correct (i.e. people able to use Loop::run() in a shutdown function).

\cc @davidwdan @trowski @mbonneau

{
self::$level = 0;
};
register_shutdown_function($f->bindTo(null, Loop::class));
Copy link
Member

Choose a reason for hiding this comment

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

Hmm... this might not be the first shutdown function to be executed.

Copy link
Member Author

Choose a reason for hiding this comment

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

I do not know of any way to prioritize that.

Copy link
Contributor

Choose a reason for hiding this comment

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

If this was done in a file included immediately by composer this would be much more likely… but still not guaranteed.

Any particular reason for requiring the level to be 0 to call Loop::run()? We don't have this restriction for execute, even when passing the loop driver returned from Loop::get().

Copy link
Member

Choose a reason for hiding this comment

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

Just not having run solves that, too.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it doesn't. you cannot use setFactory() there event though you're at top-level...

Copy link
Member

Choose a reason for hiding this comment

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

@bwoebi (1) I don't think we need setFactory() in shutdown hooks and introduce hacks for it. (2) I'd like to allow setFactory everywhere by removing the $driver = null reset here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure the limited reward justifies the added complexity here, especially since the invocation order of shutdown callbacks can't even be relied upon.

Copy link
Contributor

Choose a reason for hiding this comment

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

I pushed a commit dropping the level requirement… since shutdown function order can't be relied upon (and some apps even start the loop in a shutdown function) it just isn't worth trying to enforce it. Only so much we can do to protect users from themselves…

@kelunik
Copy link
Member

kelunik commented Jan 29, 2017

It seems like this doesn't actually solve anything. People can just use Loop::execute(function () {}, Loop::get()); and get the same result?

@@ -430,3 +455,10 @@ private function __construct()
// intentionally left blank
}
}

// Reset the $level in order to be able to use ::run() inside a shutdown handler
$f = function()
Copy link

Choose a reason for hiding this comment

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

Isn't this polluting the variable scope?

Copy link
Member Author

Choose a reason for hiding this comment

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

given the composer autoloader, no.

@kelunik kelunik mentioned this pull request Jan 31, 2017
@kelunik
Copy link
Member

kelunik commented Feb 17, 2017

Can we close this one?

@bwoebi bwoebi closed this Feb 25, 2017
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.

5 participants