Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Coroutine.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
* @return Promise
*
* @see https://github.com/petkaantonov/bluebird/blob/master/API.md#generators inspiration
* @template T
* @template-implements PromiseInterface<T>
*/
final class Coroutine implements PromiseInterface
{
Expand Down
5 changes: 4 additions & 1 deletion src/FulfilledPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
* Thenning off of this promise will invoke the onFulfilled callback
* immediately and ignore other callbacks.
*
* @template T
* @template-implements PromiseInterface<T>
*
* @final
*/
class FulfilledPromise implements PromiseInterface
{
private $value;

/**
* @param mixed $value
* @param T $value
*/
public function __construct($value)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* Promises/A+ implementation that avoids recursion when possible.
*
* @see https://promisesaplus.com/
* @template T
* @template-implements PromiseInterface<T>
*
* @final
*/
Expand Down
22 changes: 17 additions & 5 deletions src/PromiseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* the reason why the promise cannot be fulfilled.
*
* @see https://promisesaplus.com/
* @template T
*/
interface PromiseInterface
{
Expand All @@ -23,8 +24,12 @@ interface PromiseInterface
* Appends fulfillment and rejection handlers to the promise, and returns
* a new promise resolving to the return value of the called handler.
*
* @param callable $onFulfilled Invoked when the promise fulfills.
* @param callable $onRejected Invoked when the promise is rejected.
* @template U
* @template V
* @param null|callable(T): U $onFulfilled Invoked when the promise fulfills.
* @param null|callable(mixed): V $onRejected Invoked when the promise is rejected.
*
* @return ($onFulfilled is null ? ($onRejected is null ? PromiseInterface<T> : PromiseInterface<T|V>) : ($onRejected is null ? PromiseInterface<T|U> : PromiseInterface<U|V>))
*/
public function then(
?callable $onFulfilled = null,
Expand All @@ -37,7 +42,10 @@ public function then(
* or to its original fulfillment value if the promise is instead
* fulfilled.
*
* @param callable $onRejected Invoked when the promise is rejected.
* @template V
* @param callable(mixed): V $onRejected Invoked when the promise is rejected.
*
* @return PromiseInterface<T|V>
*/
public function otherwise(callable $onRejected): PromiseInterface;

Expand All @@ -46,13 +54,15 @@ public function otherwise(callable $onRejected): PromiseInterface;
*
* The three states can be checked against the constants defined on
* PromiseInterface: PENDING, FULFILLED, and REJECTED.
*
* @return 'pending'|'fulfilled'|'rejected'
*/
public function getState(): string;

/**
* Resolve the promise with the given value.
*
* @param mixed $value
* @param T $value
*
* @throws \RuntimeException if the promise is already resolved.
*/
Expand Down Expand Up @@ -82,7 +92,9 @@ public function cancel(): void;
*
* If the promise cannot be waited on, then the promise will be rejected.
*
* @return mixed
* @param bool $unwrap
*
* @return ($unwrap is true ? T : void)
*
* @throws \LogicException if the promise has no wait function or if the
* promise does not settle after waiting.
Expand Down
2 changes: 2 additions & 0 deletions src/RejectedPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* Thenning off of this promise will invoke the onRejected callback
* immediately and ignore other callbacks.
*
* @template-implements PromiseInterface<null>
*
* @final
*/
class RejectedPromise implements PromiseInterface
Expand Down