PluginProbe
DecaLog / 4.4.0
DecaLog v4.4.0
3.0.2 3.1.0 3.10.0 3.2.0 3.3.0 3.4.0 3.4.1 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.6.3 3.7.0 3.7.1 3.8.0 3.9.0 3.9.1 4.0.0 4.1.0 4.2.0 4.3.0 4.3.1 4.4.0 4.5.0 All 75 releases
decalog / includes / libraries / react / Promise / LazyPromise.php

LazyPromise.php in DecaLog 4.4.0, at includes/libraries/react/Promise/LazyPromise.php

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