mirror of
https://github.com/danog/parallel.git
synced 2024-12-12 09:09:35 +01:00
6be72c6754
Tasks on Windows must be run in-order because STDIO pipes are blocking. IPC be refactored to use sockets in the future if desired.
33 lines
798 B
PHP
33 lines
798 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) {
|
|
$this->task = $task;
|
|
$this->id = \spl_object_hash($this->task);
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|