mirror of
https://github.com/danog/amp.git
synced 2024-12-02 17:37:50 +01:00
33 lines
617 B
PHP
33 lines
617 B
PHP
<?php
|
|
|
|
namespace Amp;
|
|
|
|
use Revolt\EventLoop\Loop;
|
|
|
|
/**
|
|
* Creates a failed promise using the given exception.
|
|
*
|
|
* @template-covariant TValue
|
|
* @template-implements Promise<TValue>
|
|
*/
|
|
final class Failure implements Promise
|
|
{
|
|
private \Throwable $exception;
|
|
|
|
/**
|
|
* @param \Throwable $exception Rejection reason.
|
|
*/
|
|
public function __construct(\Throwable $exception)
|
|
{
|
|
$this->exception = $exception;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function onResolve(callable $onResolved): void
|
|
{
|
|
Loop::queue(fn () => $onResolved($this->exception, null));
|
|
}
|
|
}
|