-
-
Notifications
You must be signed in to change notification settings - Fork 241
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
Promise v3 #1157
Promise v3 #1157
Conversation
- changed ExtendedPromiseInterface to PromiseInterface - replaced Discord\Helpers\Deferred with React\Promise\Deferred - changed ->done(true function, false function) with ->then(true function)->catch(false function) - changed ->always() to ->finally() - added use React\Promise\Deferred where I think it was missing - updated $deferred->resolve() to $deferred->resolve(true) - updated $deferred->reject() to $deferred->reject(throwable)
@key2peace what is the state of this PR? Being stuck with v2 Promises (thanks, Composer, for not handling multiple versions of one package btw) means even something as banal as |
It wont be in v10, many dependencies still stuck with v2 promises about set_rejection_handle, Just be careful with your promise codes for now |
@SQKo DiscordPHP should at the very least handle the rejection path with a logger, with a log level >= warning. There is no reason to not do that since afterwards nobody could even catch the rejection currently. I think that's way better than leaving it up to the consumers to develop some quasi framework that minimizes the boilerplate for handling this for each and every registered command. I'm already looking into the code; it's just not easy to navigate around with something you have only been actively using for like 2 months... |
see #1208 This is anything but exhaustive, it just covers my most obvious use case. |
We know about it already, unfortunately the issue we are facing might be also caused by dependencies, our code is fine when web socket is not connected yet.. Regarding to your suggestion, we already considered about it, but it is wrong to log everything even those promise rejections already handled/caught by users and not respecting users configured Logger. DiscordPHP/src/Discord/Discord.php Lines 793 to 799 in ac16fdf
notice why it is logged only in websocket events because it only gets silence after websocket connected... Due to the nature of promise chain, where this library being in middle position, the ideal solution has to be implemented on user's end. |
wyrihaximus/react-cache-redis is currently locked to |
Tested with Civilizationbot and wyrihaximus/react-cache-redis ^4.5 and all is well. This introduces BC for React\Promise\resolve and React\Promise\reject and values must be passed for both: value for resolve (even null is fine) and a \Throwable for reject. Similarly v3 has deprecated functions like React\Promise\map and userland implementations will need to use React\Promise\all or React\Promise\any instead. |
$promise = coroutine([$event, 'handle'], $guild); | ||
|
||
$promise->done(function ($d) use (&$unavailable) { | ||
$promise->then(function ($d) use (&$unavailable) { |
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.
All Instances of $promise->then need to take parameters (callable $onFulfilled, callable $onRejected);
Let's get these functions either defined as $variable = function()
s or make some generic handlers we can throw in that will make relevant calls to Monolog
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.
Per the release notes; It is no longer possible to resolve a promise without a value (use null instead) or reject a promise without a reason (use Throwable instead).
src/Discord/Discord.php
Outdated
@@ -499,7 +498,7 @@ protected function handleReady(object $data) | |||
unset($unavailable[$guild->id]); | |||
} | |||
if (count($unavailable) < 1) { | |||
$guildLoad->resolve(); | |||
$guildLoad->resolve(true); |
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.
Instead of resolve(true) let's change these to resolve(null) as recommended per the release notes: https://github.com/reactphp/promise/releases/tag/v3.0.0
No description provided.