1
0
mirror of https://github.com/danog/amp.git synced 2025-01-22 13:21:16 +01:00
amp/lib/Failure.php
Aaron Piotrowski 69ec812bc0 Require PHP 7
2016-08-11 14:52:40 -05:00

37 lines
754 B
PHP

<?php
namespace Amp;
use Interop\Async\Awaitable;
use Interop\Async\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;
});
}
}
}