Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
namespace React\Promise;
4
 
5
/**
6
 * @deprecated 2.8.0 LazyPromise is deprecated and should not be used anymore.
7
 */
8
class LazyPromise implements ExtendedPromiseInterface, CancellablePromiseInterface
9
{
10
    private $factory;
11
    private $promise;
12
 
13
    public function __construct(callable $factory)
14
    {
15
        $this->factory = $factory;
16
    }
17
 
18
    public function then(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null)
19
    {
20
        return $this->promise()->then($onFulfilled, $onRejected, $onProgress);
21
    }
22
 
23
    public function done(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null)
24
    {
25
        return $this->promise()->done($onFulfilled, $onRejected, $onProgress);
26
    }
27
 
28
    public function otherwise(callable $onRejected)
29
    {
30
        return $this->promise()->otherwise($onRejected);
31
    }
32
 
33
    public function always(callable $onFulfilledOrRejected)
34
    {
35
        return $this->promise()->always($onFulfilledOrRejected);
36
    }
37
 
38
    public function progress(callable $onProgress)
39
    {
40
        return $this->promise()->progress($onProgress);
41
    }
42
 
43
    public function cancel()
44
    {
45
        return $this->promise()->cancel();
46
    }
47
 
48
    /**
49
     * @internal
50
     * @see Promise::settle()
51
     */
52
    public function promise()
53
    {
54
        if (null === $this->promise) {
55
            try {
56
                $this->promise = resolve(\call_user_func($this->factory));
57
            } catch (\Throwable $exception) {
58
                $this->promise = new RejectedPromise($exception);
59
            } catch (\Exception $exception) {
60
                $this->promise = new RejectedPromise($exception);
61
            }
62
        }
63
 
64
        return $this->promise;
65
    }
66
}