then() & catch() & finally()
/**
* This method is used to set the callback when the promise is resolved.
*/
public function then(callable $callback): Promise;
/**
* This method is used to set the callback when the promise is rejected.
*/
public function catch(callable $callback): Promise;
/**
* This method is used to set the callback when the promise is resolved or rejected.
*/
public function finally(callable $callback): Promise;$promise = new Promise(function($resolve, $reject) {
$resolve("Hello World");
});
$promise->then(fn($result) => var_dump($result))
->catch(fn($error) => var_dump($error))
->finnally(fn() => var_dump("PROMISE DONE!"));Last updated