-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Use Promise::done where possible, upgrade react/promise to allow v3 #10429
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
Conversation
composer.lockPackage changes
Dev Package changes
Settings · Docs · Powered by Private Packagist |
|
|
||
| $e = null; | ||
| $promise->then(function () { | ||
| $promise->done(function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code here might be simplified to just $promise->done() after reactphp/promise#170 is merged, needs to be proven, right now it breaks the build as the current uncaught handler does a trigger_error instead of throwing the exception.
|
The composer.lock diff comment has been updated to reflect new changes in this PR. |
5450981 to
002bd26
Compare
|
The composer.lock diff comment has been updated to reflect new changes in this PR. |
dbb1753 to
c4c4a42
Compare
c4c4a42 to
c3769b0
Compare
|
The composer.lock diff comment has been updated to reflect new changes in this PR. |
c3769b0 to
bd11910
Compare
This has now (finally) happened: https://github.com/reactphp/promise/releases/tag/v3.0.0 If there is a way I can help move this forward, please let me know. |
|
Yup I've seen that, thanks! It's on my list for next week |
|
The composer.lock diff comment has been updated to reflect new changes in this PR. |
|
Some feedback @WyriHaximus @clue:
I still need to fix a couple minor problems in FileDownloader with a fresher head, but otherwise I think this is mergeable. |
WyriHaximus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some feedback @WyriHaximus @clue:
Appreciate the feedback, let me respond in line 👍
- Overall this looks great IMO, thanks!
🎉 !
- resolve() requires an arg which is fine by me, but that means when you use it you always end up with at least a
PromiseInterface<null>. However if you do->then(function() { })you get aPromiseInterface. So IMO the latter maybe should be forbidden, or I'm not sure how to best type this if I expectnullI kinda don't care if it's void obviously as a consumer as really this is never going to be consumed either way. But if I type it asvoidthen I cannot useresolve()anymore. For now I typedPromiseInterface<void|null>but it's a bit ugly.
This one has been something we've discussed a lot and it breaks down to this: Effectively a void method translates to a null return so the promise PromiseInterface<null>. We're literally giving you back when PHP gives us: https://3v4l.org/PvkVI It took a bit for me to make sense as well tbh.
- It seems like
resolve(true);yields aPromiseInterface<bool>and that is not compatible with aPromiseInterface<true>which makes sense of course but seems like a bug, probably that's a PHPStan generics bug though.
Given how PHP now has true as return type, both should be valid I suppose?
I still need to fix a couple minor problems in FileDownloader with a fresher head, but otherwise I think this is mergeable.
Sweet, looking forward to that!
| if ($promise instanceof CancellablePromiseInterface) { | ||
| $promise->cancel(); | ||
| } | ||
| // to support react/promise 2.x we wrap the promise in a resolve() call for safety | ||
| \React\Promise\resolve($promise)->cancel(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, you can do instanceof on PromiseInterface and do a method_exists($promise, 'then').
That is what I would expect and IMO it makes sense as there is no real void type in PHP, but it doesn't seem to be what happens: Hopefully you see what I mean now. To always satisfy null one would have to explicitly return null. It's probably fine, I guess I should fix it that way because it is more semantically correct. |
|
Ok I kept the type as IMO it'd be nice if there was a phpstan extension perhaps that would convert |
@Seldaek Thanks for the feedback, glad you like the release!
Excellent question! Probably deserves a longer-form blog post, I'll put this on my list :) In a gist, there is in fact a subtle, but noticeable difference between Very similar to your above examples, this is also covered by our test suite: assertType('React\Promise\PromiseInterface<null>', resolve(null));
assertType('React\Promise\PromiseInterface<void>', resolve(null)->then(function (null $value): void { }));
assertType('React\Promise\PromiseInterface<null>', resolve(null)->then(function (null $value): void { })->then(function (null $value) { }));Semantically, the above holds true and is what should be relied upon. On a functional level, you're indeed right that a Hope this helps to clear things up a bit, but definitely warrants a longer post in the future, sponsors welcome I guess! 😉 |
@clue thanks but for me it's not quite clear why But as |
|
Im going to tag this here #11563 as it might be related and broken by this (purely speculation, as it contains the word |
|
@PhilETaylor it is related because of the end of chain detection added in v3, let me respond on that issue a bit more in-depth on your issue. |
|
Absolutely no rush - and Im not looking for support at all :) but thought best to report it early. |
Really appreciate that, it a bit BC break for our consumers of that package. But I'm excited that we already get to see it pay off this quickly 👍. |
@Seldaek Late reply, but my main point is that promise template types would always be the async equivalent of a synchronous return value, i.e.
I can see where you're coming from and agree that it's inconsistent there's no easy way to generate a |
|
Yeah I guess not worth adding a |
Needs a react/promise 3.x release to happen first, then this can be finalized