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

Minor updates and tweaks

This commit is contained in:
Aaron Piotrowski 2015-12-05 01:09:42 -06:00
parent fe9a213431
commit b994cab086
8 changed files with 16 additions and 15 deletions

View File

@ -2,13 +2,13 @@
<?php
require dirname(__DIR__).'/vendor/autoload.php';
use Icicle\Concurrent\Worker\WorkerFactory;
use Icicle\Concurrent\Worker\DefaultWorkerFactory;
use Icicle\Coroutine;
use Icicle\Examples\Concurrent\BlockingTask;
use Icicle\Loop;
Coroutine\create(function () {
$factory = new WorkerFactory();
$factory = new DefaultWorkerFactory();
$worker = $factory->create();
$worker->start();

View File

@ -2,10 +2,8 @@
namespace Icicle\Concurrent\Forking;
use Icicle\Concurrent\Exception\ForkException;
use Icicle\Concurrent\Exception\InvalidArgumentError;
use Icicle\Concurrent\Exception\StatusError;
use Icicle\Concurrent\Exception\SynchronizationError;
use Icicle\Concurrent\Exception\UnsupportedError;
use Icicle\Concurrent\Process;
use Icicle\Concurrent\Sync\Channel;
use Icicle\Concurrent\Sync\DataChannel;
@ -13,6 +11,8 @@ use Icicle\Concurrent\Sync\Internal\ExitFailure;
use Icicle\Concurrent\Sync\Internal\ExitStatus;
use Icicle\Concurrent\Sync\Internal\ExitSuccess;
use Icicle\Coroutine\Coroutine;
use Icicle\Exception\InvalidArgumentError;
use Icicle\Exception\UnsupportedError;
use Icicle\Loop;
use Icicle\Stream;
use Icicle\Stream\Pipe\DuplexPipe;

View File

@ -133,6 +133,7 @@ class Process implements ProcessContext
}
/**
* @throws \Icicle\Concurrent\Exception\ProcessException If starting the process fails.
* @throws \Icicle\Concurrent\Exception\StatusError If the process is already running.
*/
public function start()
@ -141,6 +142,8 @@ class Process implements ProcessContext
throw new StatusError('The process has already been started.');
}
$this->delayed = new Delayed();
$fd = [
['pipe', 'r'], // stdin
['pipe', 'w'], // stdout
@ -177,8 +180,6 @@ class Process implements ProcessContext
$stream = $pipes[3];
stream_set_blocking($stream, 0);
$this->delayed = new Delayed();
$this->poll = Loop\poll($stream, function ($resource) {
if (feof($resource)) {
$this->delayed->reject(new ProcessException('Process ended unexpectedly.'));

View File

@ -2,15 +2,15 @@
namespace Icicle\Concurrent\Threading;
use Icicle\Concurrent\Context;
use Icicle\Concurrent\Exception\InvalidArgumentError;
use Icicle\Concurrent\Exception\StatusError;
use Icicle\Concurrent\Exception\SynchronizationError;
use Icicle\Concurrent\Exception\ThreadException;
use Icicle\Concurrent\Exception\UnsupportedError;
use Icicle\Concurrent\Sync\Channel;
use Icicle\Concurrent\Sync\DataChannel;
use Icicle\Concurrent\Sync\Internal\ExitStatus;
use Icicle\Coroutine;
use Icicle\Exception\InvalidArgumentError;
use Icicle\Exception\UnsupportedError;
use Icicle\Stream;
use Icicle\Stream\Pipe\DuplexPipe;
@ -91,6 +91,7 @@ class Thread implements Channel, Context
* @param callable $function The callable to invoke in the thread when run.
*
* @throws InvalidArgumentError If the given function cannot be safely invoked in a thread.
* @throws UnsupportedError Thrown if the pthreads extension is not available.
*/
public function __construct(callable $function /* , ...$args */)
{

View File

@ -1,6 +1,9 @@
<?php
namespace Icicle\Concurrent\Worker;
use Icicle\Concurrent\Forking\Fork;
use Icicle\Concurrent\Threading\Thread;
/**
* The built-in worker factory type.
*/
@ -15,11 +18,11 @@ class DefaultWorkerFactory implements WorkerFactory
*/
public function create()
{
if (extension_loaded('pthreads')) {
if (Thread::enabled()) {
return new WorkerThread();
}
if (extension_loaded('pcntl')) {
if (Fork::enabled()) {
return new WorkerFork();
}

View File

@ -2,10 +2,8 @@
namespace Icicle\Tests\Concurrent;
use Icicle\Concurrent\Sync\Internal\ExitSuccess;
use Icicle\Concurrent\Forking\Fork;
use Icicle\Coroutine;
use Icicle\Loop;
use Icicle\Tests\Concurrent\TestCase;
abstract class AbstractContextTest extends TestCase
{
@ -245,7 +243,7 @@ abstract class AbstractContextTest extends TestCase
/**
* @depends testSendAndReceive
* @expectedException \Icicle\Concurrent\Exception\InvalidArgumentError
* @expectedException \Icicle\Exception\InvalidArgumentError
*/
public function testSendExitStatus()
{

View File

@ -1,7 +1,6 @@
<?php
namespace Icicle\Tests\Concurrent\Forking;
use Icicle\Concurrent\Sync\Internal\ExitSuccess;
use Icicle\Concurrent\Forking\Fork;
use Icicle\Coroutine;
use Icicle\Loop;

View File

@ -1,7 +1,6 @@
<?php
namespace Icicle\Tests\Concurrent\Threading;
use Icicle\Concurrent\Sync\Internal\ExitSuccess;
use Icicle\Concurrent\Threading\Thread;
use Icicle\Coroutine;
use Icicle\Loop;