1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-04 02:27:55 +01:00
parallel/lib/Worker/Internal/TaskFailure.php

44 lines
1.0 KiB
PHP
Raw Normal View History

2015-08-27 16:10:08 +02:00
<?php
2016-08-18 18:04:48 +02:00
namespace Amp\Concurrent\Worker\Internal;
2015-08-27 16:10:08 +02:00
2016-08-18 18:04:48 +02:00
use Amp\Concurrent\TaskException;
use Amp\Failure;
use Interop\Async\Awaitable;
class TaskFailure implements TaskResult {
/** @var string */
private $id;
/** @var string */
2015-08-27 16:10:08 +02:00
private $type;
/** @var string */
2015-08-27 16:10:08 +02:00
private $message;
/** @var int */
2015-08-27 16:10:08 +02:00
private $code;
/** @var array */
2015-08-27 16:10:08 +02:00
private $trace;
public function __construct(string $id, \Throwable $exception) {
$this->id = $id;
2015-08-27 16:10:08 +02:00
$this->type = get_class($exception);
$this->message = $exception->getMessage();
$this->code = $exception->getCode();
$this->trace = $exception->getTraceAsString();
}
public function getId(): string {
return $this->id;
}
public function getAwaitable(): Awaitable {
return new Failure(new TaskException(
2015-08-27 16:10:08 +02:00
sprintf('Uncaught exception in worker of type "%s" with message "%s"', $this->type, $this->message),
$this->code,
$this->trace
));
2015-08-27 16:10:08 +02:00
}
}