Skip to content

Commit

Permalink
Use Promise v3 template types
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonFrings committed May 2, 2024
1 parent 7c3738e commit 9102fe2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
*/
function async(callable $function): callable
{
/** @var callable(A1=,A2=,A3=,A4=,A5=): PromiseInterface<T> */
return static function (mixed ...$args) use ($function): PromiseInterface {
$fiber = null;
$promise = new Promise(function (callable $resolve, callable $reject) use ($function, $args, &$fiber): void {
Expand Down Expand Up @@ -673,6 +674,7 @@ function coroutine(callable $function, mixed ...$args): PromiseInterface
};
$next();

/** @var PromiseInterface<T> */
return $deferred->promise();
}

Expand Down Expand Up @@ -734,6 +736,7 @@ function parallel(iterable $tasks): PromiseInterface
$deferred->resolve($results);
}

/** @var PromiseInterface<array<T>> */
return $deferred->promise();
}

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

$next();

/** @var PromiseInterface<array<T>> */
return $deferred->promise();
}

Expand Down Expand Up @@ -838,5 +842,6 @@ function waterfall(iterable $tasks): PromiseInterface

$next();

/** @var PromiseInterface<T> */
return $deferred->promise();
}
6 changes: 3 additions & 3 deletions tests/AwaitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function testAwaitThrowsUnexpectedValueExceptionWhenPromiseIsRejectedWith
}

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

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

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

try {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9102fe2

Please sign in to comment.