summaryrefslogtreecommitdiff
path: root/vendor/open-telemetry/sdk/Common/Future/CompletedFuture.php
blob: 7f0cd653603f7949e7dc4b145b5a4b9888348f75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?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;
    }
}