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

Better running and kill detection

This commit is contained in:
coderstephen 2015-08-28 16:18:02 -05:00
parent 9559d32241
commit 9a4cdf7b40
2 changed files with 12 additions and 2 deletions

View File

@ -0,0 +1,6 @@
<?php
namespace Icicle\Concurrent\Exception;
class ThreadException extends Exception
{
}

View File

@ -5,6 +5,7 @@ use Icicle\Concurrent\ContextInterface;
use Icicle\Concurrent\Exception\InvalidArgumentError;
use Icicle\Concurrent\Exception\StatusError;
use Icicle\Concurrent\Exception\SynchronizationError;
use Icicle\Concurrent\Exception\ThreadException;
use Icicle\Concurrent\Sync\Channel;
use Icicle\Concurrent\Sync\ExitStatusInterface;
use Icicle\Concurrent\SynchronizableInterface;
@ -87,7 +88,7 @@ class Thread implements ContextInterface, SynchronizableInterface
*/
public function isRunning()
{
return $this->thread->isRunning();
return $this->thread->isRunning() && !$this->thread->isTerminated();
}
/**
@ -109,7 +110,10 @@ class Thread implements ContextInterface, SynchronizableInterface
*/
public function kill()
{
$this->thread->kill();
if (!$this->thread->kill()) {
throw new ThreadException('Failed to kill the thread.');
}
$this->channel->close();
fclose($this->socket);
}