1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-11 08:39:48 +01:00
parallel/lib/Worker/Internal/TaskFailure.php
2017-01-09 11:11:25 -06:00

38 lines
940 B
PHP

<?php
namespace Amp\Parallel\Worker\Internal;
use Amp\Failure;
use Amp\Parallel\TaskException;
use AsyncInterop\Promise;
class TaskFailure extends TaskResult {
/** @var string */
private $type;
/** @var string */
private $message;
/** @var int */
private $code;
/** @var array */
private $trace;
public function __construct(string $id, \Throwable $exception) {
parent::__construct($id);
$this->type = \get_class($exception);
$this->message = $exception->getMessage();
$this->code = $exception->getCode();
$this->trace = $exception->getTraceAsString();
}
public function promise(): Promise {
return new Failure(new TaskException(
$this->type,
sprintf('Uncaught exception in worker of type "%s" with message "%s"', $this->type, $this->message),
$this->code,
$this->trace
));
}
}