Closed
Description
Unless I'm reading it wrong, the documentation appears to have an issue with unhandled rejected promises.
A rejected promise will be considered "handled" if you catch the rejection reason with either the then() method, the catch() method, or the finally() method. Note that each of these methods return a new promise that may again be rejected if you re-throw an exception.
However if you are only using a finally() method it will not be considered handled() by the current implementation and an Unhandled promise rejection will be thrown.
<?php declare(strict_types = 1);
use React\EventLoop\Loop;
use React\Promise\Deferred;
require_once __DIR__ . '/../vendor/autoload.php';
$deferred = new Deferred(function() use (&$deferred) {
$deferred->reject(new \RuntimeException('Request cancelled'));
});
$promise = $deferred->promise();
$promise->finally(function() {
Loop::stop();
});
Loop::get()->futureTick(function () use (&$deferred) {
$deferred->reject(new \RuntimeException('Error'));
});
Loop::get()->run();