1
0
mirror of https://github.com/danog/amp.git synced 2024-11-27 04:24:42 +01:00
amp/lib/Failure.php

39 lines
835 B
PHP
Raw Normal View History

2016-08-18 05:25:54 +02:00
<?php declare(strict_types = 1);
2016-08-16 06:46:26 +02:00
2016-05-24 05:48:28 +02:00
namespace Amp;
2016-05-21 16:44:52 +02:00
use Interop\Async\Loop;
2016-05-21 16:44:52 +02:00
2016-06-01 19:18:11 +02:00
/**
* Creates a failed observable using the given exception.
2016-06-01 19:18:11 +02:00
*/
final class Failure implements Observable {
2016-08-18 05:25:54 +02:00
/** @var \Throwable $exception */
2016-05-21 16:44:52 +02:00
private $exception;
/**
2016-08-11 21:35:58 +02:00
* @param \Throwable $exception Rejection reason.
2016-05-21 16:44:52 +02:00
*/
2016-08-11 21:35:58 +02:00
public function __construct(\Throwable $exception) {
2016-05-21 16:44:52 +02:00
$this->exception = $exception;
}
/**
* {@inheritdoc}
*/
public function when(callable $onResolved) {
try {
$onResolved($this->exception, null);
} catch (\Throwable $exception) {
Loop::defer(static function () use ($exception) {
2016-05-21 16:44:52 +02:00
throw $exception;
});
2016-05-21 16:44:52 +02:00
}
}
/**
* {@inheritdoc}
*/
public function subscribe(callable $onNext) {}
}