1
0
mirror of https://github.com/danog/parallel.git synced 2025-01-22 22:11:11 +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) { $this->poll = Loop\poll($stream, function ($resource) {
if (!is_resource($resource) || feof($resource)) { if (!is_resource($resource) || feof($resource)) {
$this->close($resource);
$this->delayed->reject(new ProcessException('Process ended unexpectedly.')); $this->delayed->reject(new ProcessException('Process ended unexpectedly.'));
} else { } else {
$code = fread($resource, 1); $code = fread($resource, 1);
$this->close($resource);
if (!strlen($code) || !is_numeric($code)) { if (!strlen($code) || !is_numeric($code)) {
$this->delayed->reject(new ProcessException('Process ended without providing a status code.')); $this->delayed->reject(new ProcessException('Process ended without providing a status code.'));
} else { } else {
@ -193,6 +194,17 @@ class Process implements ProcessContext
} }
} }
$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)) { if (is_resource($resource)) {
fclose($resource); fclose($resource);
} }
@ -203,8 +215,6 @@ class Process implements ProcessContext
} }
$this->stdin->close(); $this->stdin->close();
$this->poll->free();
});
} }
/** /**