55use React \EventLoop \LoopInterface ;
66use React \Promise \PromiseInterface as ReactPromise ;
77use Http \Client \Exception ;
8- use Http \Promise \Promise ;
8+ use Http \Promise \Promise as HttpPromise ;
99use Psr \Http \Message \ResponseInterface ;
1010
1111/**
12- * React promise adapter implementation
12+ * React promise adapter implementation.
13+ *
1314 * @author Stéphane Hulard <[email protected] > 1415 */
15- class ReactPromiseAdapter implements Promise
16+ class Promise implements HttpPromise
1617{
1718 /**
18- * Promise status
19+ * Promise status.
20+ *
1921 * @var string
2022 */
21- private $ state = Promise ::PENDING ;
23+ private $ state = HttpPromise ::PENDING ;
2224
2325 /**
24- * Adapted React promise
26+ * Adapted React promise.
27+ *
2528 * @var ReactPromise
2629 */
2730 private $ promise ;
2831
2932 /**
30- * PSR7 received response
33+ * PSR7 received response.
34+ *
3135 * @var ResponseInterface
3236 */
3337 private $ response ;
3438
3539 /**
36- * Execution error
40+ * Execution error.
41+ *
3742 * @var Exception
3843 */
3944 private $ exception ;
4045
4146 /**
42- * React Event Loop used for synchronous processing
47+ * React Event Loop used for synchronous processing.
48+ *
4349 * @var LoopInterface
4450 */
4551 private $ loop ;
4652
4753 /**
48- * Initialize the promise
54+ * Initialize the promise.
55+ *
4956 * @param ReactPromise $promise
5057 */
5158 public function __construct (ReactPromise $ promise )
5259 {
5360 $ promise ->then (
5461 function (ResponseInterface $ response ) {
55- $ this ->state = Promise ::FULFILLED ;
62+ $ this ->state = HttpPromise ::FULFILLED ;
5663 $ this ->response = $ response ;
5764 },
5865 function (Exception $ error ) {
59- $ this ->state = Promise ::REJECTED ;
66+ $ this ->state = HttpPromise ::REJECTED ;
6067 $ this ->exception = $ error ;
6168 }
6269 );
6370 $ this ->promise = $ promise ;
6471 }
6572
6673 /**
67- * Allow to apply callable when the promise resolve
68- * @param callable|null $onFulfilled
69- * @param callable|null $onRejected
74+ * Allow to apply callable when the promise resolve.
75+ *
76+ * @param callable|null $onFulfilled
77+ * @param callable|null $onRejected
78+ *
7079 * @return ReactPromiseAdapter
7180 */
7281 public function then (callable $ onFulfilled = null , callable $ onRejected = null )
@@ -80,6 +89,7 @@ public function then(callable $onFulfilled = null, callable $onRejected = null)
8089 call_user_func ($ onRejected , $ this ->exception );
8190 }
8291 });
92+
8393 return $ this ;
8494 }
8595
@@ -92,13 +102,16 @@ public function getState()
92102 }
93103
94104 /**
95- * Set EventLoop used for synchronous processing
105+ * Set EventLoop used for synchronous processing.
106+ *
96107 * @param LoopInterface $loop
108+ *
97109 * @return ReactPromiseAdapter
98110 */
99111 public function setLoop (LoopInterface $ loop )
100112 {
101113 $ this ->loop = $ loop ;
114+
102115 return $ this ;
103116 }
104117
@@ -108,14 +121,14 @@ public function setLoop(LoopInterface $loop)
108121 public function wait ($ unwrap = true )
109122 {
110123 if (null === $ this ->loop ) {
111- throw new \LogicException (" You must set the loop before wait! " );
124+ throw new \LogicException (' You must set the loop before wait! ' );
112125 }
113- while (Promise ::PENDING === $ this ->getState ()) {
126+ while (HttpPromise ::PENDING === $ this ->getState ()) {
114127 $ this ->loop ->tick ();
115128 }
116129
117130 if ($ unwrap ) {
118- if (Promise ::REJECTED == $ this ->getState ()) {
131+ if (HttpPromise ::REJECTED == $ this ->getState ()) {
119132 throw $ this ->exception ;
120133 }
121134
0 commit comments