mirror of
https://github.com/danog/amp.git
synced 2024-11-27 04:24:42 +01:00
34 lines
755 B
PHP
34 lines
755 B
PHP
<?php declare(strict_types = 1);
|
|
|
|
namespace Amp;
|
|
|
|
use Interop\Async\{ Awaitable, Loop };
|
|
|
|
/**
|
|
* Creates a failed awaitable using the given exception.
|
|
*/
|
|
final class Failure implements Awaitable {
|
|
/** @var \Throwable $exception */
|
|
private $exception;
|
|
|
|
/**
|
|
* @param \Throwable $exception Rejection reason.
|
|
*/
|
|
public function __construct(\Throwable $exception) {
|
|
$this->exception = $exception;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function when(callable $onResolved) {
|
|
try {
|
|
$onResolved($this->exception, null);
|
|
} catch (\Throwable $exception) {
|
|
Loop::defer(static function () use ($exception) {
|
|
throw $exception;
|
|
});
|
|
}
|
|
}
|
|
}
|