~ballot/wordpress/openstack-objectstorage-bis

« back to all changes in this revision

Viewing changes to vendor/guzzlehttp/ringphp/src/Future/CompletedFutureValue.php

  • Committer: Thomas Cuthbert
  • Date: 2020-04-23 05:22:45 UTC
  • Revision ID: thomas.cuthbert@canonical.com-20200423052245-1jxao3mw31w435js
[,r=trivial] bionic composer vendor update

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
namespace GuzzleHttp\Ring\Future;
 
3
 
 
4
use React\Promise\FulfilledPromise;
 
5
use React\Promise\RejectedPromise;
 
6
 
 
7
/**
 
8
 * Represents a future value that has been resolved or rejected.
 
9
 */
 
10
class CompletedFutureValue implements FutureInterface
 
11
{
 
12
    protected $result;
 
13
    protected $error;
 
14
 
 
15
    private $cachedPromise;
 
16
 
 
17
    /**
 
18
     * @param mixed      $result Resolved result
 
19
     * @param \Exception $e      Error. Pass a GuzzleHttp\Ring\Exception\CancelledFutureAccessException
 
20
     *                           to mark the future as cancelled.
 
21
     */
 
22
    public function __construct($result, \Exception $e = null)
 
23
    {
 
24
        $this->result = $result;
 
25
        $this->error = $e;
 
26
    }
 
27
 
 
28
    public function wait()
 
29
    {
 
30
        if ($this->error) {
 
31
            throw $this->error;
 
32
        }
 
33
 
 
34
        return $this->result;
 
35
    }
 
36
 
 
37
    public function cancel() {}
 
38
 
 
39
    public function promise()
 
40
    {
 
41
        if (!$this->cachedPromise) {
 
42
            $this->cachedPromise = $this->error
 
43
                ? new RejectedPromise($this->error)
 
44
                : new FulfilledPromise($this->result);
 
45
        }
 
46
 
 
47
        return $this->cachedPromise;
 
48
    }
 
49
 
 
50
    public function then(
 
51
        callable $onFulfilled = null,
 
52
        callable $onRejected = null,
 
53
        callable $onProgress = null
 
54
    ) {
 
55
        return $this->promise()->then($onFulfilled, $onRejected, $onProgress);
 
56
    }
 
57
}