File tree Expand file tree Collapse file tree 3 files changed +13
-26
lines changed Expand file tree Collapse file tree 3 files changed +13
-26
lines changed Original file line number Diff line number Diff line change 1212 ],
1313 "require" : {
1414 "php" : " >=5.4" ,
15- "php-http/httplug" : " ^ 1.0.0-alpha2 " ,
15+ "php-http/httplug" : " 1.0.0-alpha3 " ,
1616 "php-http/message-factory" : " ^0.4@dev" ,
1717 "react/http-client" : " ^0.4.8" ,
1818 "react/dns" : " ^0.4.1" ,
Original file line number Diff line number Diff line change 99use React \HttpClient \Response as ReactResponse ;
1010use Http \Client \HttpClient ;
1111use Http \Client \HttpAsyncClient ;
12- use Http \Client \Promise ;
1312use Http \Client \Exception \HttpException ;
1413use Http \Client \Exception \RequestException ;
14+ use Http \Promise \Promise ;
1515use Http \Message \MessageFactory ;
1616use Psr \Http \Message \RequestInterface ;
1717use Psr \Http \Message \StreamInterface ;
@@ -62,13 +62,8 @@ public function __construct(
6262 public function sendRequest (RequestInterface $ request )
6363 {
6464 $ promise = $ this ->sendAsyncRequest ($ request );
65- $ promise ->wait ();
6665
67- if ($ promise ->getState () == Promise::REJECTED ) {
68- throw $ promise ->getException ();
69- }
70-
71- return $ promise ->getResponse ();
66+ return $ promise ->wait ();
7267 }
7368
7469 /**
Original file line number Diff line number Diff line change 44
55use React \EventLoop \LoopInterface ;
66use React \Promise \PromiseInterface as ReactPromise ;
7- use Http \Client \Promise ;
87use Http \Client \Exception ;
8+ use Http \Promise \Promise ;
99use Psr \Http \Message \ResponseInterface ;
1010
1111/**
@@ -91,22 +91,6 @@ public function getState()
9191 return $ this ->state ;
9292 }
9393
94- /**
95- * {@inheritdoc}
96- */
97- public function getResponse ()
98- {
99- return $ this ->response ;
100- }
101-
102- /**
103- * {@inheritdoc}
104- */
105- public function getException ()
106- {
107- return $ this ->exception ;
108- }
109-
11094 /**
11195 * Set EventLoop used for synchronous processing
11296 * @param LoopInterface $loop
@@ -121,13 +105,21 @@ public function setLoop(LoopInterface $loop)
121105 /**
122106 * {@inheritdoc}
123107 */
124- public function wait ()
108+ public function wait ($ unwrap = true )
125109 {
126110 if (null === $ this ->loop ) {
127111 throw new \LogicException ("You must set the loop before wait! " );
128112 }
129113 while (Promise::PENDING === $ this ->getState ()) {
130114 $ this ->loop ->tick ();
131115 }
116+
117+ if ($ unwrap ) {
118+ if (Promise::REJECTED == $ this ->getState ()) {
119+ throw $ this ->exception ;
120+ }
121+
122+ return $ this ->response ;
123+ }
132124 }
133125}
You can’t perform that action at this time.
0 commit comments