1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-04 18:47:50 +01:00
parallel/lib/Worker/Internal/TaskFailure.php
2017-03-16 17:03:59 -05:00

38 lines
931 B
PHP

<?php
namespace Amp\Parallel\Worker\Internal;
use Amp\Failure;
use Amp\Parallel\TaskException;
use Amp\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
));
}
}