From 51cbc60eb737ea796289d931a3454955f8122eb4 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Thu, 14 Oct 2021 21:42:08 -0500 Subject: [PATCH] Update for Revolt changes --- composer.json | 6 ++-- lib/Internal/Posix/Runner.php | 26 +++++++-------- lib/Internal/Windows/Runner.php | 12 +++---- lib/Internal/Windows/SocketConnector.php | 40 ++++++++++++------------ lib/Process.php | 4 +-- lib/ProcessInputStream.php | 4 +-- lib/ProcessOutputStream.php | 4 +-- test/ProcessTest.php | 2 +- test/bin/signal-process.php | 6 ++-- 9 files changed, 52 insertions(+), 52 deletions(-) diff --git a/composer.json b/composer.json index bf13808..d479327 100644 --- a/composer.json +++ b/composer.json @@ -4,12 +4,12 @@ "description": "Asynchronous process manager.", "require": { "php": ">=8", - "amphp/amp": "dev-v3-revolt", - "amphp/byte-stream": "dev-v2-revolt" + "amphp/amp": "v3.x-dev", + "amphp/byte-stream": "v2.x-dev" }, "require-dev": { "phpunit/phpunit": "^9", - "amphp/phpunit-util": "dev-v2-revolt", + "amphp/phpunit-util": "v2.x-dev", "amphp/php-cs-fixer-config": "dev-master" }, "prefer-stable": true, diff --git a/lib/Internal/Posix/Runner.php b/lib/Internal/Posix/Runner.php index bb2dbe5..bffc330 100644 --- a/lib/Internal/Posix/Runner.php +++ b/lib/Internal/Posix/Runner.php @@ -11,7 +11,7 @@ use Amp\Process\Internal\ProcessStatus; use Amp\Process\ProcessException; use Amp\Process\ProcessInputStream; use Amp\Process\ProcessOutputStream; -use Revolt\EventLoop\Loop; +use Revolt\EventLoop; /** @internal */ final class Runner implements ProcessRunner @@ -28,7 +28,7 @@ final class Runner implements ProcessRunner public static function onProcessEndExtraDataPipeReadable($watcher, $stream, Handle $handle): void { - Loop::cancel($watcher); + EventLoop::cancel($watcher); $handle->extraDataPipeWatcher = null; $handle->status = ProcessStatus::ENDED; @@ -42,7 +42,7 @@ final class Runner implements ProcessRunner public static function onProcessStartExtraDataPipeReadable($watcher, $stream, $data): void { - Loop::cancel($watcher); + EventLoop::cancel($watcher); $pid = \rtrim(@\fgets($stream)); @@ -69,7 +69,7 @@ final class Runner implements ProcessRunner $deferreds[2]->complete($pipes[2]); if ($handle->extraDataPipeWatcher !== null) { - Loop::enable($handle->extraDataPipeWatcher); + EventLoop::enable($handle->extraDataPipeWatcher); } } @@ -113,7 +113,7 @@ final class Runner implements ProcessRunner \stream_set_blocking($handle->extraDataPipe, false); - $handle->extraDataPipeStartWatcher = Loop::onReadable( + $handle->extraDataPipeStartWatcher = EventLoop::onReadable( $handle->extraDataPipe, static function (string $watcher, $stream) use ( $handle, @@ -134,13 +134,13 @@ final class Runner implements ProcessRunner } ); - $handle->extraDataPipeWatcher = Loop::onReadable( + $handle->extraDataPipeWatcher = EventLoop::onReadable( $handle->extraDataPipe, static fn (string $watcher, $stream) => self::onProcessEndExtraDataPipeReadable($watcher, $stream, $handle), ); - Loop::unreference($handle->extraDataPipeWatcher); - Loop::disable($handle->extraDataPipeWatcher); + EventLoop::unreference($handle->extraDataPipeWatcher); + EventLoop::disable($handle->extraDataPipeWatcher); return $handle; } @@ -174,7 +174,7 @@ final class Runner implements ProcessRunner { /** @var Handle $handle */ if ($handle->extraDataPipeWatcher !== null) { - Loop::reference($handle->extraDataPipeWatcher); + EventLoop::reference($handle->extraDataPipeWatcher); } return $handle->joinDeferred->getFuture()->await(); @@ -185,13 +185,13 @@ final class Runner implements ProcessRunner { /** @var Handle $handle */ if ($handle->extraDataPipeWatcher !== null) { - Loop::cancel($handle->extraDataPipeWatcher); + EventLoop::cancel($handle->extraDataPipeWatcher); $handle->extraDataPipeWatcher = null; } /** @var Handle $handle */ if ($handle->extraDataPipeStartWatcher !== null) { - Loop::cancel($handle->extraDataPipeStartWatcher); + EventLoop::cancel($handle->extraDataPipeStartWatcher); $handle->extraDataPipeStartWatcher = null; } @@ -241,13 +241,13 @@ final class Runner implements ProcessRunner { /** @var Handle $handle */ if ($handle->extraDataPipeWatcher !== null) { - Loop::cancel($handle->extraDataPipeWatcher); + EventLoop::cancel($handle->extraDataPipeWatcher); $handle->extraDataPipeWatcher = null; } /** @var Handle $handle */ if ($handle->extraDataPipeStartWatcher !== null) { - Loop::cancel($handle->extraDataPipeStartWatcher); + EventLoop::cancel($handle->extraDataPipeStartWatcher); $handle->extraDataPipeStartWatcher = null; } diff --git a/lib/Internal/Windows/Runner.php b/lib/Internal/Windows/Runner.php index 63b0943..fc8610f 100644 --- a/lib/Internal/Windows/Runner.php +++ b/lib/Internal/Windows/Runner.php @@ -9,7 +9,7 @@ use Amp\Process\Internal\ProcessStatus; use Amp\Process\ProcessException; use Amp\Process\ProcessInputStream; use Amp\Process\ProcessOutputStream; -use Revolt\EventLoop\Loop; +use Revolt\EventLoop; use const Amp\Process\BIN_DIR; /** @@ -113,7 +113,7 @@ final class Runner implements ProcessRunner $handle->exitCodeRequested = true; if ($handle->exitCodeWatcher !== null) { - Loop::reference($handle->exitCodeWatcher); + EventLoop::reference($handle->exitCodeWatcher); } return $handle->joinDeferred->getFuture()->await(); @@ -131,14 +131,14 @@ final class Runner implements ProcessRunner $failStart = false; if ($handle->childPidWatcher !== null) { - Loop::cancel($handle->childPidWatcher); + EventLoop::cancel($handle->childPidWatcher); $handle->childPidWatcher = null; $handle->pidDeferred->error(new ProcessException("The process was killed")); $failStart = true; } if ($handle->exitCodeWatcher !== null) { - Loop::cancel($handle->exitCodeWatcher); + EventLoop::cancel($handle->exitCodeWatcher); $handle->exitCodeWatcher = null; $handle->joinDeferred->error(new ProcessException("The process was killed")); } @@ -214,12 +214,12 @@ final class Runner implements ProcessRunner private function free(Handle $handle): void { if ($handle->childPidWatcher !== null) { - Loop::cancel($handle->childPidWatcher); + EventLoop::cancel($handle->childPidWatcher); $handle->childPidWatcher = null; } if ($handle->exitCodeWatcher !== null) { - Loop::cancel($handle->exitCodeWatcher); + EventLoop::cancel($handle->exitCodeWatcher); $handle->exitCodeWatcher = null; } diff --git a/lib/Internal/Windows/SocketConnector.php b/lib/Internal/Windows/SocketConnector.php index 55325bc..570a583 100644 --- a/lib/Internal/Windows/SocketConnector.php +++ b/lib/Internal/Windows/SocketConnector.php @@ -6,7 +6,7 @@ use Amp\ByteStream\ResourceInputStream; use Amp\ByteStream\ResourceOutputStream; use Amp\Process\Internal\ProcessStatus; use Amp\Process\ProcessException; -use Revolt\EventLoop\Loop; +use Revolt\EventLoop; /** * @internal @@ -44,12 +44,12 @@ final class SocketConnector [$this->address, $port] = \explode(':', \stream_socket_get_name($this->server, false)); $this->port = (int) $port; - Loop::unreference(Loop::onReadable($this->server, [$this, 'onServerSocketReadable'])); + EventLoop::unreference(EventLoop::onReadable($this->server, [$this, 'onServerSocketReadable'])); } public function failHandleStart(Handle $handle, string $message, ...$args) { - Loop::cancel($handle->connectTimeoutWatcher); + EventLoop::cancel($handle->connectTimeoutWatcher); unset($this->pendingProcesses[$handle->wrapperPid]); @@ -126,7 +126,7 @@ final class SocketConnector $pendingClient->pid = (int) $packet['pid']; $pendingClient->streamId = (int) $packet['stream_id']; - $pendingClient->readWatcher = Loop::onReadable($socket, [$this, 'onReadableHandshakeAck']); + $pendingClient->readWatcher = EventLoop::onReadable($socket, [$this, 'onReadableHandshakeAck']); } public function onReadableHandshakeAck($watcher, $socket) @@ -137,8 +137,8 @@ final class SocketConnector // can happen if the start promise was failed if (!isset($this->pendingProcesses[$pendingClient->pid]) || $this->pendingProcesses[$pendingClient->pid]->status === ProcessStatus::ENDED) { \fclose($socket); - Loop::cancel($watcher); - Loop::cancel($pendingClient->timeoutWatcher); + EventLoop::cancel($watcher); + EventLoop::cancel($pendingClient->timeoutWatcher); unset($this->pendingClients[$socketId]); return; } @@ -147,7 +147,7 @@ final class SocketConnector return; } - Loop::cancel($pendingClient->timeoutWatcher); + EventLoop::cancel($pendingClient->timeoutWatcher); unset($this->pendingClients[$socketId]); $handle = $this->pendingProcesses[$pendingClient->pid]; @@ -167,7 +167,7 @@ final class SocketConnector $handle->sockets[$pendingClient->streamId] = $socket; if (\count($handle->sockets) === 3) { - $handle->childPidWatcher = Loop::onReadable($handle->sockets[0], [$this, 'onReadableChildPid'], $handle); + $handle->childPidWatcher = EventLoop::onReadable($handle->sockets[0], [$this, 'onReadableChildPid'], $handle); $deferreds = $handle->stdioDeferreds; $handle->stdioDeferreds = []; // clear, so there's no double resolution if process spawn fails @@ -186,8 +186,8 @@ final class SocketConnector return; } - Loop::cancel($handle->childPidWatcher); - Loop::cancel($handle->connectTimeoutWatcher); + EventLoop::cancel($handle->childPidWatcher); + EventLoop::cancel($handle->connectTimeoutWatcher); $handle->childPidWatcher = null; @@ -214,10 +214,10 @@ final class SocketConnector // Required, because a process might be destroyed while starting if ($handle->status === ProcessStatus::STARTING) { $handle->status = ProcessStatus::RUNNING; - $handle->exitCodeWatcher = Loop::onReadable($handle->sockets[0], [$this, 'onReadableExitCode'], $handle); + $handle->exitCodeWatcher = EventLoop::onReadable($handle->sockets[0], [$this, 'onReadableExitCode'], $handle); if (!$handle->exitCodeRequested) { - Loop::unreference($handle->exitCodeWatcher); + EventLoop::unreference($handle->exitCodeWatcher); } } @@ -234,7 +234,7 @@ final class SocketConnector return; } - Loop::cancel($handle->exitCodeWatcher); + EventLoop::cancel($handle->exitCodeWatcher); $handle->exitCodeWatcher = null; if (\strlen($data) !== 5) { @@ -275,7 +275,7 @@ final class SocketConnector { $id = (int) $socket; - Loop::cancel($this->pendingClients[$id]->readWatcher); + EventLoop::cancel($this->pendingClients[$id]->readWatcher); unset($this->pendingClients[$id]); \fclose($socket); @@ -290,8 +290,8 @@ final class SocketConnector } $pendingClient = new PendingSocketClient; - $pendingClient->readWatcher = Loop::onReadable($socket, [$this, 'onReadableHandshake']); - $pendingClient->timeoutWatcher = Loop::delay( + $pendingClient->readWatcher = EventLoop::onReadable($socket, [$this, 'onReadableHandshake']); + $pendingClient->timeoutWatcher = EventLoop::delay( self::CONNECT_TIMEOUT, [$this, 'onClientSocketConnectTimeout'], $socket @@ -327,10 +327,10 @@ final class SocketConnector public function registerPendingProcess(Handle $handle) { - // Use Loop::defer() to start the timeout only after the loop has ticked once. This prevents issues with many + // Use EventLoop::defer() to start the timeout only after the loop has ticked once. This prevents issues with many // things started at once, see https://github.com/amphp/process/issues/21. - $handle->connectTimeoutWatcher = Loop::defer(function () use ($handle) { - $handle->connectTimeoutWatcher = Loop::delay( + $handle->connectTimeoutWatcher = EventLoop::defer(function () use ($handle) { + $handle->connectTimeoutWatcher = EventLoop::delay( self::CONNECT_TIMEOUT, [$this, 'onProcessConnectTimeout'], $handle @@ -376,7 +376,7 @@ final class SocketConnector $state->receivedDataBuffer = ''; - Loop::cancel($state->readWatcher); + EventLoop::cancel($state->readWatcher); return $data; } diff --git a/lib/Process.php b/lib/Process.php index 720f081..0a53c34 100644 --- a/lib/Process.php +++ b/lib/Process.php @@ -7,7 +7,7 @@ use Amp\Process\Internal\ProcessHandle; use Amp\Process\Internal\ProcessRunner; use Amp\Process\Internal\ProcessStatus; use Amp\Process\Internal\Windows\Runner as WindowsProcessRunner; -use Revolt\EventLoop\Loop; +use Revolt\EventLoop; final class Process { @@ -60,7 +60,7 @@ final class Process $this->env = $envVars; $this->options = $options; - $driver = Loop::getDriver(); + $driver = EventLoop::getDriver(); $this->processRunner = ( self::$map[$driver] ??= (IS_WINDOWS ? new WindowsProcessRunner() : new PosixProcessRunner()) diff --git a/lib/ProcessInputStream.php b/lib/ProcessInputStream.php index 679eae4..134d96c 100644 --- a/lib/ProcessInputStream.php +++ b/lib/ProcessInputStream.php @@ -8,7 +8,7 @@ use Amp\ByteStream\ResourceInputStream; use Amp\ByteStream\StreamException; use Amp\Deferred; use Amp\Future; -use function Revolt\EventLoop\queue; +use function Revolt\launch; final class ProcessInputStream implements InputStream { @@ -24,7 +24,7 @@ final class ProcessInputStream implements InputStream public function __construct(Future $resourceStreamFuture) { - queue(function () use ($resourceStreamFuture): void { + launch(function () use ($resourceStreamFuture): void { try { $this->resourceStream = $resourceStreamFuture->await(); diff --git a/lib/ProcessOutputStream.php b/lib/ProcessOutputStream.php index df28462..ab1caf1 100644 --- a/lib/ProcessOutputStream.php +++ b/lib/ProcessOutputStream.php @@ -8,7 +8,7 @@ use Amp\ByteStream\ResourceOutputStream; use Amp\ByteStream\StreamException; use Amp\Deferred; use Amp\Future; -use function Revolt\EventLoop\queue; +use function Revolt\launch; final class ProcessOutputStream implements OutputStream { @@ -26,7 +26,7 @@ final class ProcessOutputStream implements OutputStream { $this->queuedWrites = new \SplQueue; - queue(function () use ($resourceStreamFuture): void { + launch(function () use ($resourceStreamFuture): void { try { $resourceStream = $resourceStreamFuture->await(); diff --git a/test/ProcessTest.php b/test/ProcessTest.php index 04c6cf3..3f94703 100644 --- a/test/ProcessTest.php +++ b/test/ProcessTest.php @@ -281,7 +281,7 @@ class ProcessTest extends AsyncTestCase $promises[] = coroutine(fn () => $process->join()); } - self::assertSame(\range(0, $count - 1), Future\all($promises)); + self::assertEquals(\range(0, $count - 1), Future\all($promises)); } public function testReadOutputAfterExit() diff --git a/test/bin/signal-process.php b/test/bin/signal-process.php index 922334b..4551f75 100644 --- a/test/bin/signal-process.php +++ b/test/bin/signal-process.php @@ -1,10 +1,10 @@ exit(42))); Amp\delay(1);