1
0
mirror of https://github.com/danog/amp.git synced 2025-01-22 21:31:18 +01:00
amp/lib/Deferred.php
Aaron Piotrowski 7e30ee0c2c
Import Future
Co-authored-by: Niklas Keller <me@kelunik.com>
2021-08-29 12:18:05 -05:00

58 lines
1.1 KiB
PHP

<?php
namespace Amp;
/**
* @template T
*/
final class Deferred
{
/** @var Internal\FutureState<T> */
private Internal\FutureState $state;
/** @var Future<T> */
private Future $future;
public function __construct()
{
$this->state = new Internal\FutureState();
$this->future = new Future($this->state);
}
/**
* Completes the operation with a result value.
*
* @param T $result Result of the operation.
*/
public function complete(mixed $result): void
{
$this->state->complete($result);
}
/**
* Marks the operation as failed.
*
* @param \Throwable $throwable Throwable to indicate the error.
*/
public function error(\Throwable $throwable): void
{
$this->state->error($throwable);
}
/**
* @return bool True if the operation has completed.
*/
public function isComplete(): bool
{
return $this->state->isComplete();
}
/**
* @return Future<T> The future associated with this Deferred.
*/
public function getFuture(): Future
{
return $this->future;
}
}