diff options
Diffstat (limited to 'vendor/open-telemetry/sdk/Common/Future/ErrorFuture.php')
-rw-r--r-- | vendor/open-telemetry/sdk/Common/Future/ErrorFuture.php | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/vendor/open-telemetry/sdk/Common/Future/ErrorFuture.php b/vendor/open-telemetry/sdk/Common/Future/ErrorFuture.php new file mode 100644 index 000000000..32cf3d995 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Future/ErrorFuture.php @@ -0,0 +1,40 @@ +<?php + +declare(strict_types=1); + +namespace OpenTelemetry\SDK\Common\Future; + +use Closure; +use Throwable; + +final class ErrorFuture implements FutureInterface +{ + private Throwable $throwable; + + public function __construct(Throwable $throwable) + { + $this->throwable = $throwable; + } + + public function await() + { + throw $this->throwable; + } + + public function map(Closure $closure): FutureInterface + { + return $this; + } + + public function catch(Closure $closure): FutureInterface + { + $c = $closure; + unset($closure); + + try { + return new CompletedFuture($c($this->throwable)); + } catch (Throwable $e) { + return new ErrorFuture($e); + } + } +} |