Skip to content

Commit 1400c28

Browse files
committed
Use Promise v3 template types
1 parent 7c3738e commit 1400c28

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/functions.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ function async(callable $function): callable
191191
{
192192
return static function (mixed ...$args) use ($function): PromiseInterface {
193193
$fiber = null;
194+
/** @var PromiseInterface<T> $promise*/
194195
$promise = new Promise(function (callable $resolve, callable $reject) use ($function, $args, &$fiber): void {
195196
$fiber = new \Fiber(function () use ($resolve, $reject, $function, $args, &$fiber): void {
196197
try {
@@ -627,6 +628,7 @@ function coroutine(callable $function, mixed ...$args): PromiseInterface
627628
}
628629

629630
$promise = null;
631+
/** @var Deferred<T> $deferred*/
630632
$deferred = new Deferred(function () use (&$promise) {
631633
/** @var ?PromiseInterface<T> $promise */
632634
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
@@ -734,6 +736,7 @@ function parallel(iterable $tasks): PromiseInterface
734736
$deferred->resolve($results);
735737
}
736738

739+
/** @var PromiseInterface<array<T>> Can't define `Deferred()` above, currently not supported by PHPStan, see https://github.com/phpstan/phpstan/issues/11032 */
737740
return $deferred->promise();
738741
}
739742

@@ -789,6 +792,7 @@ function series(iterable $tasks): PromiseInterface
789792

790793
$next();
791794

795+
/** @var PromiseInterface<array<T>> Can't define `Deferred()` above, currently not supported by PHPStan, see https://github.com/phpstan/phpstan/issues/11032 */
792796
return $deferred->promise();
793797
}
794798

@@ -800,6 +804,7 @@ function series(iterable $tasks): PromiseInterface
800804
function waterfall(iterable $tasks): PromiseInterface
801805
{
802806
$pending = null;
807+
/** @var Deferred<T> $deferred*/
803808
$deferred = new Deferred(function () use (&$pending) {
804809
/** @var ?PromiseInterface<T> $pending */
805810
if ($pending instanceof PromiseInterface && \method_exists($pending, 'cancel')) {

tests/AwaitTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function testAwaitThrowsUnexpectedValueExceptionWhenPromiseIsRejectedWith
129129
}
130130

131131
$promise = new Promise(function ($_, $reject) {
132-
$reject(false);
132+
$reject(false); // @phpstan-ignore-line
133133
});
134134

135135
$this->expectException(\UnexpectedValueException::class);
@@ -147,7 +147,7 @@ public function testAwaitThrowsUnexpectedValueExceptionWhenPromiseIsRejectedWith
147147
}
148148

149149
$promise = new Promise(function ($_, $reject) {
150-
$reject(null);
150+
$reject(null); // @phpstan-ignore-line
151151
});
152152

153153
try {
@@ -331,7 +331,7 @@ public function testAwaitShouldNotCreateAnyGarbageReferencesForPromiseRejectedWi
331331
gc_collect_cycles();
332332

333333
$promise = new Promise(function ($_, $reject) {
334-
$reject(null);
334+
$reject(null); // @phpstan-ignore-line
335335
});
336336
try {
337337
$await($promise);

0 commit comments

Comments
 (0)