1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-02 17:52:14 +01:00
parallel/lib/Worker/Internal/worker-parallel.php

32 lines
766 B
PHP
Raw Normal View History

2019-02-13 21:19:01 +01:00
<?php
namespace Amp\Parallel\Worker\Internal;
use Amp\Parallel\Sync;
use Amp\Parallel\Worker;
use Amp\Promise;
return function (Sync\Channel $channel, string $className): Promise {
if (!\defined("AMP_WORKER")) {
\define("AMP_WORKER", "parallel");
}
if (!\class_exists($className)) {
throw new \Error(\sprintf("Invalid environment class name '%s'", $className));
}
if (!\is_subclass_of($className, Worker\Environment::class)) {
throw new \Error(\sprintf(
"The class '%s' does not implement '%s'",
$className,
Worker\Environment::class
));
}
$environment = new $className;
$runner = new Worker\TaskRunner($channel, $environment);
return $runner->run();
};