1
0
mirror of https://github.com/danog/process.git synced 2024-11-30 04:39:04 +01:00

Make process runner loop bound

This commit is contained in:
Niklas Keller 2017-09-19 15:35:43 +02:00
parent b9264a7ad3
commit f99b93c2ca
2 changed files with 18 additions and 26 deletions

View File

@ -2,6 +2,7 @@
namespace Amp\Process;
use Amp\Loop;
use Amp\Process\Internal\Posix\Runner as PosixProcessRunner;
use Amp\Process\Internal\ProcessHandle;
use Amp\Process\Internal\ProcessRunner;
@ -11,7 +12,7 @@ use Amp\Promise;
class Process {
/** @var ProcessRunner */
private static $processRunner;
private $processRunner;
/** @var string */
private $command;
@ -57,6 +58,16 @@ class Process {
$this->cwd = $cwd;
$this->env = $envVars;
$this->options = $options;
$this->processRunner = Loop::getState(self::class);
if ($this->processRunner === null) {
$this->processRunner = \strncasecmp(\PHP_OS, "WIN", 3) === 0
? new WindowsProcessRunner
: new PosixProcessRunner;
Loop::setState(self::class, $this->processRunner);
}
}
/**
@ -64,7 +75,7 @@ class Process {
*/
public function __destruct() {
if ($this->handle !== null) {
self::$processRunner->destroy($this->handle);
$this->processRunner->destroy($this->handle);
}
}
@ -82,7 +93,7 @@ class Process {
throw new StatusError("Process has already been started.");
}
$this->handle = self::$processRunner->start($this->command, $this->cwd, $this->env, $this->options);
$this->handle = $this->processRunner->start($this->command, $this->cwd, $this->env, $this->options);
}
/**
@ -97,7 +108,7 @@ class Process {
throw new StatusError("Process has not been started.");
}
return self::$processRunner->join($this->handle);
return $this->processRunner->join($this->handle);
}
/**
@ -111,7 +122,7 @@ class Process {
throw new StatusError("The process is not running");
}
self::$processRunner->kill($this->handle);
$this->processRunner->kill($this->handle);
}
/**
@ -127,7 +138,7 @@ class Process {
throw new StatusError("The process is not running");
}
self::$processRunner->signal($this->handle, $signo);
$this->processRunner->signal($this->handle, $signo);
}
/**
@ -229,10 +240,3 @@ class Process {
return $this->handle->stderr;
}
}
(function () {
/** @noinspection PhpUndefinedClassInspection */
self::$processRunner = \strncasecmp(\PHP_OS, "WIN", 3) === 0
? new WindowsProcessRunner
: new PosixProcessRunner;
})->bindTo(null, Process::class)();

View File

@ -1,17 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.0/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="Amp Process">
<directory>test</directory>