1
0
mirror of https://github.com/danog/amp.git synced 2024-11-30 04:29:08 +01:00
amp/lib/Failure.php
Aaron Piotrowski 754a29e86c Remove promise error handler
Exceptions thrown from when callbacks are now forwarded directly to the loop error handler.
2017-03-10 15:32:58 -06:00

38 lines
792 B
PHP

<?php
namespace Amp;
/**
* Creates a failed stream (which is also a promise) using the given exception.
*/
final class Failure implements Stream {
/** @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(function () use ($exception) {
throw $exception;
});
}
}
/**
* {@inheritdoc}
*/
public function listen(callable $onNext) {
}
}