From 9102fe278e093d0aa110b5e2c3da7a6d792ee50d Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Thu, 2 May 2024 14:24:44 +0200 Subject: [PATCH] Use Promise v3 template types --- src/functions.php | 5 +++++ tests/AwaitTest.php | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/functions.php b/src/functions.php index 6c27936..c00761a 100644 --- a/src/functions.php +++ b/src/functions.php @@ -189,6 +189,7 @@ */ function async(callable $function): callable { + /** @var callable(A1=,A2=,A3=,A4=,A5=): PromiseInterface */ return static function (mixed ...$args) use ($function): PromiseInterface { $fiber = null; $promise = new Promise(function (callable $resolve, callable $reject) use ($function, $args, &$fiber): void { @@ -673,6 +674,7 @@ function coroutine(callable $function, mixed ...$args): PromiseInterface }; $next(); + /** @var PromiseInterface */ return $deferred->promise(); } @@ -734,6 +736,7 @@ function parallel(iterable $tasks): PromiseInterface $deferred->resolve($results); } + /** @var PromiseInterface> */ return $deferred->promise(); } @@ -789,6 +792,7 @@ function series(iterable $tasks): PromiseInterface $next(); + /** @var PromiseInterface> */ return $deferred->promise(); } @@ -838,5 +842,6 @@ function waterfall(iterable $tasks): PromiseInterface $next(); + /** @var PromiseInterface */ return $deferred->promise(); } diff --git a/tests/AwaitTest.php b/tests/AwaitTest.php index 25e269b..7eced26 100644 --- a/tests/AwaitTest.php +++ b/tests/AwaitTest.php @@ -129,7 +129,7 @@ public function testAwaitThrowsUnexpectedValueExceptionWhenPromiseIsRejectedWith } $promise = new Promise(function ($_, $reject) { - $reject(false); + $reject(false); // @phpstan-ignore-line }); $this->expectException(\UnexpectedValueException::class); @@ -147,7 +147,7 @@ public function testAwaitThrowsUnexpectedValueExceptionWhenPromiseIsRejectedWith } $promise = new Promise(function ($_, $reject) { - $reject(null); + $reject(null); // @phpstan-ignore-line }); try { @@ -331,7 +331,7 @@ public function testAwaitShouldNotCreateAnyGarbageReferencesForPromiseRejectedWi gc_collect_cycles(); $promise = new Promise(function ($_, $reject) { - $reject(null); + $reject(null); // @phpstan-ignore-line }); try { $await($promise);