Skip to content
Snippets Groups Projects
Unverified Commit c25665f6 authored by David Buchmann's avatar David Buchmann Committed by GitHub
Browse files

Merge pull request #27 from Ndiritu/Radiergummi/add-generic-annotations

Refactor Promise classes with generic types (fast-tracking https://github.com/php-http/promise/pull/24)
parents cac94eb6 465dae0e
No related branches found
No related tags found
No related merge requests found
# Change Log # Change Log
### Added
- Generic annotations
## 1.1.0 - 2020-07-07 ## 1.1.0 - 2020-07-07
### Added ### Added
......
...@@ -6,14 +6,21 @@ namespace Http\Promise; ...@@ -6,14 +6,21 @@ namespace Http\Promise;
* A promise already fulfilled. * A promise already fulfilled.
* *
* @author Joel Wurtz <joel.wurtz@gmail.com> * @author Joel Wurtz <joel.wurtz@gmail.com>
*
* @template-covariant T
*
* @implements Promise<T>
*/ */
final class FulfilledPromise implements Promise final class FulfilledPromise implements Promise
{ {
/** /**
* @var mixed * @var T
*/ */
private $result; private $result;
/**
* @param T $result
*/
public function __construct($result) public function __construct($result)
{ {
$this->result = $result; $this->result = $result;
......
...@@ -12,6 +12,8 @@ namespace Http\Promise; ...@@ -12,6 +12,8 @@ namespace Http\Promise;
* *
* @author Joel Wurtz <joel.wurtz@gmail.com> * @author Joel Wurtz <joel.wurtz@gmail.com>
* @author Márk Sági-Kazár <mark.sagikazar@gmail.com> * @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
*
* @template-covariant T
*/ */
interface Promise interface Promise
{ {
...@@ -36,10 +38,12 @@ interface Promise ...@@ -36,10 +38,12 @@ interface Promise
* If you do not care about one of the cases, you can set the corresponding callable to null * If you do not care about one of the cases, you can set the corresponding callable to null
* The callback will be called when the value arrived and never more than once. * The callback will be called when the value arrived and never more than once.
* *
* @param callable|null $onFulfilled called when a response will be available * @param callable(T): V|null $onFulfilled called when a response will be available
* @param callable|null $onRejected called when an exception occurs * @param callable(\Exception): V|null $onRejected called when an exception occurs
*
* @return Promise<V> a new resolved promise with value of the executed callback (onFulfilled / onRejected)
* *
* @return Promise a new resolved promise with value of the executed callback (onFulfilled / onRejected) * @template V
*/ */
public function then(callable $onFulfilled = null, callable $onRejected = null); public function then(callable $onFulfilled = null, callable $onRejected = null);
...@@ -61,7 +65,7 @@ interface Promise ...@@ -61,7 +65,7 @@ interface Promise
* *
* @param bool $unwrap Whether to return resolved value / throw reason or not * @param bool $unwrap Whether to return resolved value / throw reason or not
* *
* @return mixed Resolved value, null if $unwrap is set to false * @return T Resolved value, null if $unwrap is set to false
* *
* @throws \Exception the rejection reason if $unwrap is set to true and the request failed * @throws \Exception the rejection reason if $unwrap is set to true and the request failed
*/ */
......
...@@ -6,6 +6,10 @@ namespace Http\Promise; ...@@ -6,6 +6,10 @@ namespace Http\Promise;
* A rejected promise. * A rejected promise.
* *
* @author Joel Wurtz <joel.wurtz@gmail.com> * @author Joel Wurtz <joel.wurtz@gmail.com>
*
* @template-covariant T
*
* @implements Promise<T>
*/ */
final class RejectedPromise implements Promise final class RejectedPromise implements Promise
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment