1
0
mirror of https://github.com/danog/parallel.git synced 2025-01-22 14:01:14 +01:00

Close stream and process before resolving delayed

This commit is contained in:
Aaron Piotrowski 2016-02-21 10:36:01 -06:00
parent 85e730f4f0
commit c9b9aa148f

View File

@ -182,10 +182,11 @@ class Process implements ProcessContext
$this->poll = Loop\poll($stream, function ($resource) {
if (!is_resource($resource) || feof($resource)) {
$this->close($resource);
$this->delayed->reject(new ProcessException('Process ended unexpectedly.'));
} else {
$code = fread($resource, 1);
$this->close($resource);
if (!strlen($code) || !is_numeric($code)) {
$this->delayed->reject(new ProcessException('Process ended without providing a status code.'));
} else {
@ -193,20 +194,29 @@ class Process implements ProcessContext
}
}
if (is_resource($resource)) {
fclose($resource);
}
if (is_resource($this->process)) {
proc_close($this->process);
$this->process = null;
}
$this->stdin->close();
$this->poll->free();
});
}
/**
* Closes the stream resource provided, the open process handle, and stdin.
*
* @param resource $resource
*/
private function close($resource)
{
if (is_resource($resource)) {
fclose($resource);
}
if (is_resource($this->process)) {
proc_close($this->process);
$this->process = null;
}
$this->stdin->close();
}
/**
* @coroutine
*