PHP Luminova: Rejected Promise Object
Use Luminova’s Deferred, Fulfilled, and Rejected classes to simplify promise handling, manage pre-resolved states, and improve async logic clarity.
The Rejected class represents a promise that is already rejected with a specific error or exception.It's useful for returning an immediate failure state from a function that normally returns a promise.
Class Definition
- Class Namespace:
Luminova\Promise\Rejected - Implements: \Luminova\Interface\PromiseInterface
constructor
Creates a promise that is already rejected.
public __construct(\Throwable $reason)Parameters
| Parameter | Type | Description |
|---|---|---|
$reason | Throwable | The reason for the rejection, typically an exception or error. |
Usage
use Luminova\Promise\Rejected;
$promise = new Rejected(new \Exception('An error occurred'));
$promise->catch(function (\Throwable $error) {
echo "Error: " . $error->getMessage(); // Output: Error: An error occurred
});