mirror of
https://github.com/danog/amp.git
synced 2024-11-27 04:24:42 +01:00
38 lines
797 B
PHP
38 lines
797 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 onResolve(callable $onResolved) {
|
|
try {
|
|
$onResolved($this->exception, null);
|
|
} catch (\Throwable $exception) {
|
|
Loop::defer(function () use ($exception) {
|
|
throw $exception;
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function onEmit(callable $onEmit) {
|
|
}
|
|
}
|