Skip to content
This repository was archived by the owner on Jan 6, 2024. It is now read-only.

Commit e8ae36e

Browse files
committed
Merge pull request #15 from php-http/feature/promise
Update async call with new promise package and interface update
2 parents 2103114 + 1a32411 commit e8ae36e

File tree

2 files changed

+9
-26
lines changed

2 files changed

+9
-26
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
],
1717
"require": {
1818
"php": ">=5.5.0",
19-
"php-http/httplug": "^1.0@dev",
19+
"php-http/httplug": "1.0.0-alpha3",
2020
"php-http/client-tools": "^0.1@dev",
2121
"guzzlehttp/guzzle": "^6.0"
2222
},

src/Guzzle6Promise.php

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use GuzzleHttp\Exception as GuzzleExceptions;
66
use GuzzleHttp\Promise\PromiseInterface;
77
use Http\Client\Exception as HttplugException;
8-
use Http\Client\Promise;
8+
use Http\Promise\Promise;
99
use Psr\Http\Message\RequestInterface;
1010
use Psr\Http\Message\ResponseInterface;
1111

@@ -89,37 +89,20 @@ public function getState()
8989
return $this->state;
9090
}
9191

92-
9392
/**
9493
* {@inheritdoc}
9594
*/
96-
public function getResponse()
95+
public function wait($unwrap = true)
9796
{
98-
if (self::FULFILLED !== $this->state) {
99-
throw new \LogicException("Response not available for the current state");
100-
}
97+
$this->promise->wait(false);
10198

102-
return $this->response;
103-
}
99+
if ($unwrap) {
100+
if ($this->getState() == self::REJECTED) {
101+
throw $this->exception;
102+
}
104103

105-
/**
106-
* {@inheritdoc}
107-
*/
108-
public function getException()
109-
{
110-
if (self::REJECTED !== $this->state) {
111-
throw new \LogicException("Error not available for the current state");
104+
return $this->response;
112105
}
113-
114-
return $this->exception;
115-
}
116-
117-
/**
118-
* {@inheritdoc}
119-
*/
120-
public function wait()
121-
{
122-
$this->promise->wait(false);
123106
}
124107

125108
/**

0 commit comments

Comments
 (0)