1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-03 18:17:52 +01:00
parallel/lib/Worker/Internal/Job.php
Aaron Piotrowski fc4c2a07b7
Shorten job IDs
2017-12-13 21:28:08 -06:00

35 lines
801 B
PHP

<?php
namespace Amp\Parallel\Worker\Internal;
use Amp\Parallel\Worker\Task;
/** @internal */
class Job {
/** @var string */
private $id;
/** @var \Amp\Parallel\Worker\Task */
private $task;
public function __construct(Task $task) {
static $id = 'a';
$this->task = $task;
$this->id = $id++;
}
public function getId(): string {
return $this->id;
}
public function getTask(): Task {
// Classes that cannot be autoloaded will be unserialized as an instance of __PHP_Incomplete_Class.
if ($this->task instanceof \__PHP_Incomplete_Class) {
throw new \Error(\sprintf("Classes implementing %s must be autoloadable by the Composer autoloader", Task::class));
}
return $this->task;
}
}