Skip to content

Commit

Permalink
Update react/promise
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jun 3, 2024
1 parent cbdc933 commit da754e2
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 43 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"react/dns": "^1.10",
"react/event-loop": "^1.2",
"react/http": "^1.1",
"react/promise": "^2.8",
"react/promise": "^3.2",
"react/socket": "^1.3",
"react/stream": "^1.1",
"symfony/console": "^5.4.3",
Expand Down
19 changes: 10 additions & 9 deletions composer.lock

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

20 changes: 0 additions & 20 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -139,26 +139,6 @@ parameters:
count: 1
path: src/Command/ErrorsConsoleStyle.php

-
message: "#^Call to an undefined method React\\\\Promise\\\\PromiseInterface\\<Psr\\\\Http\\\\Message\\\\ResponseInterface\\>\\:\\:done\\(\\)\\.$#"
count: 1
path: src/Command/FixerApplication.php

-
message: "#^Unable to resolve the template type T in call to function React\\\\Async\\\\await$#"
count: 1
path: src/Command/FixerApplication.php

-
message: "#^Call to an undefined method React\\\\Promise\\\\PromiseInterface\\<React\\\\Socket\\\\ConnectionInterface\\>\\:\\:done\\(\\)\\.$#"
count: 1
path: src/Command/FixerWorkerCommand.php

-
message: "#^Call to an undefined method React\\\\Promise\\\\PromiseInterface\\<React\\\\Socket\\\\ConnectionInterface\\>\\:\\:done\\(\\)\\.$#"
count: 1
path: src/Command/WorkerCommand.php

-
message: "#^Variable method call on Nette\\\\Schema\\\\Elements\\\\AnyOf\\|Nette\\\\Schema\\\\Elements\\\\Structure\\|Nette\\\\Schema\\\\Elements\\\\Type\\.$#"
count: 1
Expand Down
11 changes: 5 additions & 6 deletions src/Command/FixerApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
use React\EventLoop\LoopInterface;
use React\EventLoop\StreamSelectLoop;
use React\Http\Browser;
use React\Promise\CancellablePromiseInterface;
use React\Promise\ExtendedPromiseInterface;
use React\Promise\PromiseInterface;
use React\Socket\ConnectionInterface;
use React\Socket\Connector;
use React\Socket\TcpServer;
Expand Down Expand Up @@ -64,8 +63,8 @@
class FixerApplication
{

/** @var (ExtendedPromiseInterface&CancellablePromiseInterface)|null */
private $processInProgress;
/** @var PromiseInterface<string>|null */
private PromiseInterface|null $processInProgress = null;

private bool $fileMonitorActive = true;

Expand Down Expand Up @@ -348,7 +347,7 @@ private function downloadPhar(
throw new ShouldNotHappenException(sprintf('Could not open file %s for writing.', $pharPath));
}
$progressBar = new ProgressBar($output);
$client->requestStreaming('GET', $latestInfo['url'])->done(static function (ResponseInterface $response) use ($progressBar, $pharPathResource): void {
$client->requestStreaming('GET', $latestInfo['url'])->then(static function (ResponseInterface $response) use ($progressBar, $pharPathResource): void {
$body = $response->getBody();
if (!$body instanceof ReadableStreamInterface) {
throw new ShouldNotHappenException();
Expand Down Expand Up @@ -470,7 +469,7 @@ private function analyse(
));
$this->processInProgress = $process->run();

$this->processInProgress->done(function () use ($server): void {
$this->processInProgress->then(function () use ($server): void {
$this->processInProgress = null;
$server->close();
}, function (Throwable $e) use ($server, $output, $phpstanFixerEncoder): void {
Expand Down
3 changes: 2 additions & 1 deletion src/Command/FixerWorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$loop = new StreamSelectLoop();
$tcpConnector = new TcpConnector($loop);
$tcpConnector->connect(sprintf('127.0.0.1:%d', $serverPort))->done(function (ConnectionInterface $connection) use ($container, $inceptionResult, $configuration, $input, $ignoredErrorHelperResult, $loop): void {
$tcpConnector->connect(sprintf('127.0.0.1:%d', $serverPort))->then(function (ConnectionInterface $connection) use ($container, $inceptionResult, $configuration, $input, $ignoredErrorHelperResult, $loop): void {
// phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
$jsonInvalidUtf8Ignore = defined('JSON_INVALID_UTF8_IGNORE') ? JSON_INVALID_UTF8_IGNORE : 0;
// phpcs:enable
Expand Down Expand Up @@ -314,6 +314,7 @@ private function filterErrors(array $errors, IgnoredErrorHelperResult $ignoredEr
/**
* @param string[] $files
* @param callable(list<Error>, list<Error>, string[]): void $onFileAnalysisHandler
* @return PromiseInterface<AnalyserResult>
*/
private function runAnalyser(LoopInterface $loop, Container $container, array $files, ?string $configuration, InputInterface $input, callable $onFileAnalysisHandler): PromiseInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Command/WorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$analysedFiles = array_fill_keys($analysedFiles, true);

$tcpConnector = new TcpConnector($loop);
$tcpConnector->connect(sprintf('127.0.0.1:%d', $port))->done(function (ConnectionInterface $connection) use ($container, $identifier, $output, $analysedFiles): void {
$tcpConnector->connect(sprintf('127.0.0.1:%d', $port))->then(function (ConnectionInterface $connection) use ($container, $identifier, $output, $analysedFiles): void {
// phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
$jsonInvalidUtf8Ignore = defined('JSON_INVALID_UTF8_IGNORE') ? JSON_INVALID_UTF8_IGNORE : 0;
// phpcs:enable
Expand Down
2 changes: 2 additions & 0 deletions src/Parallel/ParallelAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function __construct(
/**
* @param Closure(int ): void|null $postFileCallback
* @param (callable(list<Error>, list<Error>, string[]): void)|null $onFileAnalysisHandler
* @return PromiseInterface<AnalyserResult>
*/
public function analyse(
LoopInterface $loop,
Expand Down Expand Up @@ -83,6 +84,7 @@ public function analyse(
$reachedInternalErrorsCountLimit = false;
$exportedNodes = [];

/** @var Deferred<AnalyserResult> $deferred */
$deferred = new Deferred();

$server = new TcpServer('127.0.0.1:0', $loop);
Expand Down
12 changes: 7 additions & 5 deletions src/Process/ProcessPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
use PHPStan\ShouldNotHappenException;
use React\ChildProcess\Process;
use React\EventLoop\LoopInterface;
use React\Promise\CancellablePromiseInterface;
use React\Promise\Deferred;
use React\Promise\ExtendedPromiseInterface;
use React\Promise\PromiseInterface;
use function fclose;
use function rewind;
use function stream_get_contents;
Expand All @@ -16,6 +15,7 @@
class ProcessPromise
{

/** @var Deferred<string> */
private Deferred $deferred;

private ?Process $process = null;
Expand All @@ -33,9 +33,9 @@ public function getName(): string
}

/**
* @return ExtendedPromiseInterface&CancellablePromiseInterface
* @return PromiseInterface<string>
*/
public function run(): CancellablePromiseInterface
public function run(): PromiseInterface
{
$tmpStdOutResource = tmpfile();
if ($tmpStdOutResource === false) {
Expand Down Expand Up @@ -72,14 +72,16 @@ public function run(): CancellablePromiseInterface
}

if ($exitCode === 0) {
if ($stdOut === false) {
$stdOut = '';
}
$this->deferred->resolve($stdOut);
return;
}

$this->deferred->reject(new ProcessCrashedException($stdOut . $stdErr));
});

/** @var ExtendedPromiseInterface&CancellablePromiseInterface */
return $this->deferred->promise();
}

Expand Down

0 comments on commit da754e2

Please sign in to comment.