Skip to content

Template types with async/await API #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
],
"require": {
"php": "^8.2",
"react/promise": "^3",
"wyrihaximus/pool-info": "^2"
},
"require-dev": {
Expand Down
148 changes: 74 additions & 74 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions src/PoolInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
namespace ReactParallel\Contracts;

use Closure;
use React\Promise\PromiseInterface;
use WyriHaximus\PoolInfo\PoolInfoInterface;

interface PoolInterface extends PoolInfoInterface
{
/**
* @param (Closure():(PromiseInterface<T>|T)) $callable
* @param array<mixed> $args
* @param (Closure():T) $callable
* @param array<mixed> $args
*
* @return PromiseInterface<T>
* @return T
*
* @template T
*/
public function run(Closure $callable, array $args = []): PromiseInterface;
public function run(Closure $callable, array $args = []): mixed;

/**
* Gently close every thread in the pool.
Expand Down
13 changes: 5 additions & 8 deletions tests/MockPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
namespace ReactParallel\Tests\Contracts;

use Closure;
use React\Promise\PromiseInterface;
use WyriHaximus\PoolInfo\PoolInfoInterface;

use function React\Promise\resolve;

final class MockPool implements PoolInfoInterface
{
/** @return iterable<string, int> */
Expand All @@ -19,16 +16,16 @@ public function info(): iterable
}

/**
* @param (Closure():(PromiseInterface<T>|T)) $callable
* @param array<mixed> $args
* @param (Closure():T) $callable
* @param array<mixed> $args
*
* @return PromiseInterface<T>
* @return T
*
* @template T
*/
public function run(Closure $callable, array $args = []): PromiseInterface
public function run(Closure $callable, array $args = []): mixed
{
return resolve($callable(...$args));
return $callable(...$args);
}

public function close(): bool
Expand Down
4 changes: 2 additions & 2 deletions tests/Types.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

$pool = new MockPool();

assertType('React\Promise\PromiseInterface<bool>', $pool->run(static function (): bool {
assertType('bool', $pool->run(static function (): bool {
return true;
}));

assertType('React\Promise\PromiseInterface<bool|int>', $pool->run(static function (): bool|int {
assertType('bool|int', $pool->run(static function (): bool|int {
return time() % 2 !== 0 ? true : time();
}));