mirror of
https://github.com/danog/parallel.git
synced 2024-12-02 17:52:14 +01:00
38 lines
968 B
PHP
38 lines
968 B
PHP
<?php declare(strict_types = 1);
|
|
|
|
namespace Amp\Parallel\Worker\Internal;
|
|
|
|
use Amp\Failure;
|
|
use Amp\Parallel\TaskException;
|
|
use Interop\Async\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
|
|
));
|
|
}
|
|
} |