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

55 lines
1.2 KiB
PHP
Raw Normal View History

2015-08-27 09:10:08 -05:00
#!/usr/bin/env php
<?php
// Redirect all output written using echo, print, printf, etc. to STDERR.
ob_start(function ($data) {
fwrite(STDERR, $data);
return '';
}, 1, 0);
2015-08-27 09:10:08 -05:00
$paths = [
dirname(dirname(dirname(__DIR__))) . '/autoload.php',
dirname(__DIR__) . '/vendor/autoload.php',
2015-08-27 09:10:08 -05:00
];
foreach ($paths as $path) {
if (file_exists($path)) {
$autoloadPath = $path;
break;
}
}
if (!isset($autoloadPath)) {
fwrite(STDERR, 'Could not locate autoload.php.');
exit(1);
2015-08-27 09:10:08 -05:00
}
require $autoloadPath;
use Icicle\Concurrent\Sync\Channel;
2015-08-29 02:13:14 -05:00
use Icicle\Concurrent\Sync\Internal\ExitFailure;
use Icicle\Concurrent\Sync\Internal\ExitSuccess;
2015-08-27 09:10:08 -05:00
use Icicle\Concurrent\Worker\Internal\TaskRunner;
use Icicle\Coroutine;
2015-08-27 09:10:08 -05:00
use Icicle\Loop;
use Icicle\Socket\Stream\ReadableStream;
use Icicle\Socket\Stream\WritableStream;
Coroutine\create(function () {
$channel = new Channel(new ReadableStream(STDIN), new WritableStream(STDOUT));
$runner = new TaskRunner($channel);
try {
$result = new ExitSuccess(yield $runner->run());
} catch (Exception $exception) {
$result = new ExitFailure($exception);
}
yield $channel->send($result);
$channel->close();
})->done();
Loop\run();