1
0
mirror of https://github.com/danog/amp.git synced 2025-01-22 21:31:18 +01:00
amp/lib/Failure.php

38 lines
797 B
PHP
Raw Normal View History

<?php
2016-08-15 23:46:26 -05:00
2016-05-23 22:48:28 -05:00
namespace Amp;
2016-05-21 09:44:52 -05:00
2016-06-01 12:18:11 -05:00
/**
2017-01-03 19:10:27 -06:00
* Creates a failed stream (which is also a promise) using the given exception.
2016-06-01 12:18:11 -05:00
*/
2017-01-03 19:10:27 -06:00
final class Failure implements Stream {
2016-08-17 22:25:54 -05:00
/** @var \Throwable $exception */
2016-05-21 09:44:52 -05:00
private $exception;
/**
2016-08-11 14:35:58 -05:00
* @param \Throwable $exception Rejection reason.
2016-05-21 09:44:52 -05:00
*/
2016-08-11 14:35:58 -05:00
public function __construct(\Throwable $exception) {
2016-05-21 09:44:52 -05:00
$this->exception = $exception;
}
/**
* {@inheritdoc}
*/
public function onResolve(callable $onResolved) {
2016-05-21 09:44:52 -05:00
try {
$onResolved($this->exception, null);
} catch (\Throwable $exception) {
Loop::defer(function () use ($exception) {
throw $exception;
});
2016-05-21 09:44:52 -05:00
}
}
/**
* {@inheritdoc}
*/
public function onEmit(callable $onEmit) {
}
}