ttrss/vendor/open-telemetry/sdk/Common/Future/CompletedFuture.php

49 lines
834 B
PHP
Raw Normal View History

2023-10-20 14:12:29 +00:00
<?php
declare(strict_types=1);
namespace OpenTelemetry\SDK\Common\Future;
use Closure;
use Throwable;
/**
* @template T
* @template-implements FutureInterface<T>
*/
final class CompletedFuture implements FutureInterface
{
/** @var T */
private $value;
/**
* @param T $value
*/
public function __construct($value)
{
$this->value = $value;
}
public function await()
{
return $this->value;
}
public function map(Closure $closure): FutureInterface
{
$c = $closure;
unset($closure);
try {
return new CompletedFuture($c($this->value));
} catch (Throwable $e) {
return new ErrorFuture($e);
}
}
public function catch(Closure $closure): FutureInterface
{
return $this;
}
}