2016-12-29 21:09:49 +01:00
|
|
|
<?php
|
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
|
|
|
|
2017-03-10 21:58:46 +01:00
|
|
|
use Amp\Promise\ErrorHandler;
|
2016-05-21 16:44:52 +02:00
|
|
|
|
2016-06-01 19:18:11 +02:00
|
|
|
/**
|
2017-01-04 02:10:27 +01:00
|
|
|
* Creates a failed stream (which is also a promise) using the given exception.
|
2016-06-01 19:18:11 +02:00
|
|
|
*/
|
2017-01-04 02:10:27 +01:00
|
|
|
final class Failure implements Stream {
|
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) {
|
2016-12-29 21:09:49 +01:00
|
|
|
ErrorHandler::notify($exception);
|
2016-05-21 16:44:52 +02:00
|
|
|
}
|
|
|
|
}
|
2017-01-07 13:47:45 +01:00
|
|
|
|
2016-08-22 23:21:47 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2017-03-10 21:58:46 +01:00
|
|
|
public function listen(callable $onNext) {
|
|
|
|
}
|
2016-05-22 20:43:37 +02:00
|
|
|
}
|