1
0
mirror of https://github.com/danog/parallel.git synced 2025-01-22 14:01:14 +01:00
parallel/lib/Worker/Internal/TaskFailure.php

38 lines
931 B
PHP
Raw Normal View History

2016-12-29 19:16:04 -06:00
<?php
2015-08-27 09:10:08 -05:00
2016-08-23 16:47:40 -05:00
namespace Amp\Parallel\Worker\Internal;
2015-08-27 09:10:08 -05:00
use Amp\Failure;
2016-08-23 16:47:40 -05:00
use Amp\Parallel\TaskException;
use Amp\Promise;
2016-09-07 11:38:46 -05:00
class TaskFailure extends TaskResult {
/** @var string */
2015-08-27 09:10:08 -05:00
private $type;
/** @var string */
2015-08-27 09:10:08 -05:00
private $message;
/** @var int */
2015-08-27 09:10:08 -05:00
private $code;
/** @var array */
2015-08-27 09:10:08 -05:00
private $trace;
public function __construct(string $id, \Throwable $exception) {
2016-09-07 11:38:46 -05:00
parent::__construct($id);
2016-09-01 18:10:52 -05:00
$this->type = \get_class($exception);
2015-08-27 09:10:08 -05:00
$this->message = $exception->getMessage();
$this->code = $exception->getCode();
$this->trace = $exception->getTraceAsString();
}
2016-11-14 17:43:44 -06:00
public function promise(): Promise {
return new Failure(new TaskException(
$this->type,
2015-08-27 09:10:08 -05:00
sprintf('Uncaught exception in worker of type "%s" with message "%s"', $this->type, $this->message),
$this->code,
$this->trace
));
2015-08-27 09:10:08 -05:00
}
}