2016-12-30 02:16:04 +01:00
|
|
|
<?php
|
2016-08-21 17:33:39 +02:00
|
|
|
|
2016-08-23 23:47:40 +02:00
|
|
|
namespace Amp\Parallel\Worker\Internal;
|
2016-08-21 17:33:39 +02:00
|
|
|
|
2018-10-24 05:10:12 +02:00
|
|
|
use Amp\Failure;
|
|
|
|
use Amp\Parallel\Worker\Task;
|
2017-03-16 23:03:59 +01:00
|
|
|
use Amp\Promise;
|
2017-05-18 09:51:31 +02:00
|
|
|
use Amp\Success;
|
2016-08-21 17:33:39 +02:00
|
|
|
|
2017-07-28 06:49:20 +02:00
|
|
|
/** @internal */
|
2018-10-21 17:54:46 +02:00
|
|
|
final class TaskSuccess extends TaskResult
|
2018-10-07 16:50:45 +02:00
|
|
|
{
|
2016-08-21 17:33:39 +02:00
|
|
|
/** @var mixed Result of task. */
|
|
|
|
private $result;
|
2017-05-18 09:51:31 +02:00
|
|
|
|
2018-10-07 16:50:45 +02:00
|
|
|
public function __construct(string $id, $result)
|
|
|
|
{
|
2016-09-07 18:38:46 +02:00
|
|
|
parent::__construct($id);
|
2016-08-21 17:33:39 +02:00
|
|
|
$this->result = $result;
|
|
|
|
}
|
2017-05-18 09:51:31 +02:00
|
|
|
|
2018-10-07 16:50:45 +02:00
|
|
|
public function promise(): Promise
|
|
|
|
{
|
2018-10-24 05:10:12 +02:00
|
|
|
if ($this->result instanceof \__PHP_Incomplete_Class) {
|
|
|
|
return new Failure(new \Error(\sprintf(
|
|
|
|
"Class instances returned from %s::run() must be autoloadable by the Composer autoloader",
|
|
|
|
Task::class
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
2016-08-21 17:33:39 +02:00
|
|
|
return new Success($this->result);
|
|
|
|
}
|
|
|
|
}
|