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

39 lines
819 B
PHP
Raw Normal View History

2016-12-30 02:16:04 +01:00
<?php
2016-08-23 23:47:40 +02:00
namespace Amp\Parallel\Worker\Internal;
2016-08-23 23:47:40 +02:00
use Amp\Parallel\Worker\Task;
2017-07-28 06:49:20 +02:00
/** @internal */
2018-10-21 17:54:46 +02:00
final class Job
2018-10-07 16:50:45 +02:00
{
/** @var string */
private $id;
2017-05-18 09:51:31 +02:00
2016-08-23 23:47:40 +02:00
/** @var \Amp\Parallel\Worker\Task */
private $task;
2017-05-18 09:51:31 +02:00
2018-10-07 16:50:45 +02:00
public function __construct(Task $task)
{
2017-12-14 04:28:08 +01:00
static $id = 'a';
$this->task = $task;
2017-12-14 04:28:08 +01:00
$this->id = $id++;
}
2017-05-18 09:51:31 +02:00
2018-10-07 16:50:45 +02:00
public function getId(): string
{
return $this->id;
}
2017-05-18 09:51:31 +02:00
2018-10-07 16:50:45 +02:00
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;
}
}