PluginProbe
WP-Stateless – Google Cloud Storage / 2.1.4
WP-Stateless – Google Cloud Storage v2.1.4
4.4.3 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.3.0 2.3.1 2.3.2 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 All 62 releases
wp-stateless / lib / Google / vendor / react / promise / src / LazyPromise.php

LazyPromise.php in WP-Stateless – Google Cloud Storage 2.1.4, at lib/Google/vendor/react/promise/src/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