1
0
mirror of https://github.com/danog/amp.git synced 2025-01-22 13:21:16 +01:00

Add further generics for static analysis

This commit is contained in:
Niklas Keller 2020-03-28 13:52:48 +01:00
parent f717dce636
commit 01cd49994f
4 changed files with 21 additions and 8 deletions

View File

@ -59,8 +59,8 @@ final class Coroutine implements Promise
/**
* @param \Generator $generator
* @psalm-param \Generator<mixed, Promise|ReactPromise|array<array-key, Promise|ReactPromise>, mixed, TReturn>
* $generator
* @psalm-param \Generator<mixed,Promise|ReactPromise|array<array-key,
* Promise|ReactPromise>,mixed,Promise<TReturn>|ReactPromise|TReturn> $generator
*/
public function __construct(\Generator $generator)
{

View File

@ -4,6 +4,9 @@ namespace Amp;
/**
* Creates a promise that resolves itself with a given value after a number of milliseconds.
*
* @template-covariant TReturn
* @template-implements Promise<TReturn>
*/
final class Delayed implements Promise
{
@ -14,7 +17,7 @@ final class Delayed implements Promise
/**
* @param int $time Milliseconds before succeeding the promise.
* @param mixed $value Succeed the promise with this value.
* @param TReturn $value Succeed the promise with this value.
*/
public function __construct(int $time, $value = null)
{

View File

@ -6,6 +6,8 @@ use React\Promise\PromiseInterface as ReactPromise;
/**
* Creates a failed promise using the given exception.
*
* @template-implements Promise<?>
*/
final class Failure implements Promise
{

View File

@ -49,10 +49,13 @@ namespace Amp
* Calls the given function, always returning a promise. If the function returns a Generator, it will be run as a
* coroutine. If the function throws, a failed promise will be returned.
*
* @param callable(mixed ...$args):\Generator|mixed $callback
* @template TReturn
*
* @param callable(mixed ...$args):(\Generator<mixed,Promise|ReactPromise|array<array-key, Promise|ReactPromise>,mixed,Promise<TReturn>|ReactPromise|TReturn>|Promise<TReturn>|ReactPromise|TReturn)
* $callback
* @param mixed ...$args Arguments to pass to the function.
*
* @return \Amp\Promise
* @return Promise<TReturn>
*/
function call(callable $callback, ...$args): Promise
{
@ -81,9 +84,14 @@ namespace Amp
* Calls the given function. If the function returns a Generator, it will be run as a coroutine. If the function
* throws or returns a failing promise, the failure is forwarded to the loop error handler.
*
* @param callable(mixed ...$args):\Generator|mixed $callback
* @template TReturn
*
* @param callable(mixed ...$args):(\Generator<mixed,Promise|ReactPromise|array<array-key, Promise|ReactPromise>,mixed,Promise<TReturn>|ReactPromise|TReturn>|Promise<TReturn>|ReactPromise|TReturn)
* $callback
* @param mixed ...$args
*
* @return void
*
* @throws \TypeError
*/
function asyncCall(callable $callback, ...$args)
@ -98,7 +106,7 @@ namespace Amp
*
* @return Delayed
*/
function delay(int $milliseconds): Promise
function delay(int $milliseconds): Delayed
{
return new Delayed($milliseconds);
}