mirror of
https://github.com/danog/process.git
synced 2024-11-26 20:24:43 +01:00
Update for Revolt changes
This commit is contained in:
parent
51c944b56e
commit
51cbc60eb7
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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())
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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()
|
||||
|
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
use Revolt\EventLoop;
|
||||
|
||||
require \dirname(__DIR__, 2) . '/vendor/autoload.php';
|
||||
|
||||
Revolt\EventLoop\Loop::unreference(Revolt\EventLoop\Loop::onSignal(\SIGTERM, function (): void {
|
||||
exit(42);
|
||||
}));
|
||||
EventLoop::unreference(EventLoop::onSignal(\SIGTERM, fn () => exit(42)));
|
||||
|
||||
Amp\delay(1);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user