Skip to content

Commit 226b3f2

Browse files
authored
Merge pull request #89 from clue-labs/templates-v3
[3.x] Improve type safety for test environment
2 parents bc3ef67 + 3404f63 commit 226b3f2

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/functions.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ function coroutine(callable $function, ...$args): PromiseInterface
323323
}
324324

325325
$promise = null;
326+
/** @var Deferred<T> $deferred*/
326327
$deferred = new Deferred(function () use (&$promise) {
327328
/** @var ?PromiseInterface<T> $promise */
328329
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
@@ -381,6 +382,7 @@ function parallel(iterable $tasks): PromiseInterface
381382
{
382383
/** @var array<int,PromiseInterface<T>> $pending */
383384
$pending = [];
385+
/** @var Deferred<array<T>> $deferred */
384386
$deferred = new Deferred(function () use (&$pending) {
385387
foreach ($pending as $promise) {
386388
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
@@ -430,6 +432,7 @@ function parallel(iterable $tasks): PromiseInterface
430432
$deferred->resolve($results);
431433
}
432434

435+
/** @var PromiseInterface<array<T>> Remove once defining `Deferred()` above is supported by PHPStan, see https://github.com/phpstan/phpstan/issues/11032 */
433436
return $deferred->promise();
434437
}
435438

@@ -441,6 +444,7 @@ function parallel(iterable $tasks): PromiseInterface
441444
function series(iterable $tasks): PromiseInterface
442445
{
443446
$pending = null;
447+
/** @var Deferred<array<T>> $deferred */
444448
$deferred = new Deferred(function () use (&$pending) {
445449
/** @var ?PromiseInterface<T> $pending */
446450
if ($pending instanceof PromiseInterface && \method_exists($pending, 'cancel')) {
@@ -485,6 +489,7 @@ function series(iterable $tasks): PromiseInterface
485489

486490
$next();
487491

492+
/** @var PromiseInterface<array<T>> Remove once defining `Deferred()` above is supported by PHPStan, see https://github.com/phpstan/phpstan/issues/11032 */
488493
return $deferred->promise();
489494
}
490495

@@ -496,6 +501,7 @@ function series(iterable $tasks): PromiseInterface
496501
function waterfall(iterable $tasks): PromiseInterface
497502
{
498503
$pending = null;
504+
/** @var Deferred<T> $deferred*/
499505
$deferred = new Deferred(function () use (&$pending) {
500506
/** @var ?PromiseInterface<T> $pending */
501507
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
@@ -26,7 +26,7 @@ public function testAwaitThrowsUnexpectedValueExceptionWhenPromiseIsRejectedWith
2626
}
2727

2828
$promise = new Promise(function ($_, $reject) {
29-
$reject(false);
29+
$reject(false); // @phpstan-ignore-line
3030
});
3131

3232
$this->expectException(\UnexpectedValueException::class);
@@ -41,7 +41,7 @@ public function testAwaitThrowsUnexpectedValueExceptionWhenPromiseIsRejectedWith
4141
}
4242

4343
$promise = new Promise(function ($_, $reject) {
44-
$reject(null);
44+
$reject(null); // @phpstan-ignore-line
4545
});
4646

4747
$this->expectException(\UnexpectedValueException::class);
@@ -278,7 +278,7 @@ public function testAwaitShouldNotCreateAnyGarbageReferencesForPromiseRejectedWi
278278
gc_collect_cycles();
279279

280280
$promise = new Promise(function ($_, $reject) {
281-
$reject(null);
281+
$reject(null); // @phpstan-ignore-line
282282
});
283283
try {
284284
React\Async\await($promise);

0 commit comments

Comments
 (0)