Debug data for promises #551
-
Please add something to help debugging the code written via promises. Closues-based code makes stacktrace useless, and without stacktrace debugging some mostly working remote code is barely possible. On Node.js there is whole layer of knowledge exists to cope with it. I think I also saw there custom promises implementation which solve it in some way. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I guess simplest way to do it is using PHP 8 attributes. Then code may look like: $client = new React\Http\Browser();
$client->get('http://www.google.com/')->then(#[StepName('handle-response')] function (Psr\Http\Message\ResponseInterface $response) {
throw new \Exception('Dummy exception.');
})->catch(function (\Throwable $reason, ?string $stepName) {
file_put_contents(STDERR, "Exception: ".$reason->getMessage()." in step ".$stepName);
}); Or in more general way: $client = new React\Http\Browser();
$client->get('http://www.google.com/')->then(#[StepName('handle-response')] function (Psr\Http\Message\ResponseInterface $response) {
throw new \Exception('Dummy exception.');
})->catch(function (\Throwable $reason, ?Closure $fn) {
//...
}); |
Beta Was this translation helpful? Give feedback.
-
Hey @EligiusSantori, I can understand that this makes working with promises, especially when it comes to debugging, somewhat more complex. This is one of the reasons why we released v4 of our reactphp/asnyc package, so you can simply use With this all said, I think it would make more sense to invest the time to move towards a ReactPHP v3/v4, as promises will move more and more into the background. Thanks for bringing in your idea, hope this gives some insights into our plans for ReactPHP and helps you proceed :) |
Beta Was this translation helpful? Give feedback.
Hey @EligiusSantori, I can understand that this makes working with promises, especially when it comes to debugging, somewhat more complex. This is one of the reasons why we released v4 of our reactphp/asnyc package, so you can simply use
async()
andawait()
on PHP 8.1+ without caring too much about promises. If you're using a PHP version below 8.1, you can also use coroutines, which work in a similar way. Additionally, the more we approach the future of ReactPHP (ReactPHP v3 & v4), the less you have to deal with promises in general.With this all said, I think it would make more sense to invest the time to move towards a ReactPHP v3/v4, as promises will move more and more into the backgro…