1
0
mirror of https://github.com/danog/amp.git synced 2024-11-27 04:24:42 +01:00
amp/lib/Failure.php
Aaron Piotrowski 5651240615 Update to promise spec v0.3
Dropped strict-types due to spec requiring weak types in callbacks.
2016-12-29 16:29:27 -06:00

37 lines
758 B
PHP

<?php
namespace Amp;
use Interop\Async\Promise\ErrorHandler;
/**
* Creates a failed observable using the given exception.
*/
final class Failure implements Observable {
/** @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) {
ErrorHandler::notify($exception);
}
}
/**
* {@inheritdoc}
*/
public function subscribe(callable $onNext) {}
}