Skip to content

Commit f690b16

Browse files
committed
Merge remote-tracking branch 'jsor/promise-2.0'
* jsor/promise-2.0: Add note to CHANGELOG Update to React/Promise 2.0
2 parents 489bf68 + 3e54f6f commit f690b16

File tree

14 files changed

+55
-54
lines changed

14 files changed

+55
-54
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
* BC break: [HttpClient] Drop unused `Response::getBody()`
99
* BC break: Bump minimum PHP version to PHP 5.4, remove 5.3 specific hacks
1010
* BC break: Remove `$loop` argument from `HttpClient`: `Client`, `Request`, `Response`
11+
* BC break: Update to React/Promise 2.0
1112
* Bug fix: [Dns] Properly resolve CNAME aliases
1213
* Bug fix: [EventLoop] No error on removing non-existent streams (@clue)
1314
* Bug fix: [EventLoop] Do not silently remove feof listeners in `LibEvLoop`

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"php": ">=5.4.0",
1212
"evenement/evenement": "1.0.*",
1313
"guzzle/parser": "~3.0",
14-
"react/promise": "~1.0"
14+
"react/promise": "~2.0"
1515
},
1616
"replace": {
1717
"react/event-loop": "self.version",

composer.lock

Lines changed: 12 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/React/Cache/ArrayCache.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace React\Cache;
44

5-
use React\Promise\When;
5+
use React\Promise;
66

77
class ArrayCache implements CacheInterface
88
{
@@ -11,10 +11,10 @@ class ArrayCache implements CacheInterface
1111
public function get($key)
1212
{
1313
if (!isset($this->data[$key])) {
14-
return When::reject();
14+
return Promise\reject();
1515
}
1616

17-
return When::resolve($this->data[$key]);
17+
return Promise\resolve($this->data[$key]);
1818
}
1919

2020
public function set($key, $value)

src/React/Dns/Config/FilesystemFactory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace React\Dns\Config;
44

55
use React\EventLoop\LoopInterface;
6+
use React\Promise;
67
use React\Promise\Deferred;
7-
use React\Promise\When;
88
use React\Stream\Stream;
99

1010
class FilesystemFactory
@@ -38,13 +38,13 @@ public function parseEtcResolvConf($contents)
3838
$config = new Config();
3939
$config->nameservers = $nameservers;
4040

41-
return When::resolve($config);
41+
return Promise\resolve($config);
4242
}
4343

4444
public function loadEtcResolvConf($filename)
4545
{
4646
if (!file_exists($filename)) {
47-
return When::reject(new \InvalidArgumentException("The filename for /etc/resolv.conf given does not exist: $filename"));
47+
return Promise\reject(new \InvalidArgumentException("The filename for /etc/resolv.conf given does not exist: $filename"));
4848
}
4949

5050
try {
@@ -68,7 +68,7 @@ public function loadEtcResolvConf($filename)
6868

6969
return $deferred->promise();
7070
} catch (\Exception $e) {
71-
return When::reject($e);
71+
return Promise\reject($e);
7272
}
7373
}
7474
}

src/React/Dns/Query/CachedExecutor.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use React\Dns\Model\Message;
66
use React\Dns\Model\Record;
7-
use React\Promise\When;
87

98
class CachedExecutor implements ExecutorInterface
109
{

src/React/Dns/Query/RecordCache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use React\Cache\CacheInterface;
66
use React\Dns\Model\Message;
77
use React\Dns\Model\Record;
8-
use React\Promise\When;
8+
use React\Promise;
99

1010
class RecordCache
1111
{
@@ -29,7 +29,7 @@ public function lookup(Query $query)
2929
$recordBag = unserialize($value);
3030

3131
if (null !== $expiredAt && $expiredAt <= $query->currentTime) {
32-
return When::reject();
32+
return Promise\reject();
3333
}
3434

3535
return $recordBag->all();

src/React/Dns/Query/RetryExecutor.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ public function query($nameserver, Query $query)
1919
{
2020
$deferred = new Deferred();
2121

22-
$this->tryQuery($nameserver, $query, $this->retries, $deferred->resolver());
22+
$this->tryQuery($nameserver, $query, $this->retries, $deferred);
2323

2424
return $deferred->promise();
2525
}
2626

27-
public function tryQuery($nameserver, Query $query, $retries, $resolver)
27+
public function tryQuery($nameserver, Query $query, $retries, $deferred)
2828
{
29-
$errorback = function ($error) use ($nameserver, $query, $retries, $resolver) {
29+
$errorback = function ($error) use ($nameserver, $query, $retries, $deferred) {
3030
if (!$error instanceof TimeoutException) {
31-
$resolver->reject($error);
31+
$deferred->reject($error);
3232
return;
3333
}
3434
if (0 >= $retries) {
@@ -37,14 +37,14 @@ public function tryQuery($nameserver, Query $query, $retries, $resolver)
3737
0,
3838
$error
3939
);
40-
$resolver->reject($error);
40+
$deferred->reject($error);
4141
return;
4242
}
43-
$this->tryQuery($nameserver, $query, $retries-1, $resolver);
43+
$this->tryQuery($nameserver, $query, $retries-1, $deferred);
4444
};
4545

4646
$this->executor
4747
->query($nameserver, $query)
48-
->then(array($resolver, 'resolve'), $errorback);
48+
->then(array($deferred, 'resolve'), $errorback);
4949
}
5050
}

src/React/SocketClient/Connector.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use React\EventLoop\LoopInterface;
66
use React\Dns\Resolver\Resolver;
77
use React\Stream\Stream;
8-
use React\Promise\When;
8+
use React\Promise;
99
use React\Promise\Deferred;
1010

1111
class Connector implements ConnectorInterface
@@ -35,7 +35,7 @@ public function createSocketForAddress($address, $port)
3535
$socket = stream_socket_client($url, $errno, $errstr, 0, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT);
3636

3737
if (!$socket) {
38-
return When::reject(new \RuntimeException(
38+
return Promise\reject(new \RuntimeException(
3939
sprintf("connection to %s:%d failed: %s", $address, $port, $errstr),
4040
$errno
4141
));
@@ -71,10 +71,10 @@ public function checkConnectedSocket($socket)
7171
// The following hack looks like the only way to
7272
// detect connection refused errors with PHP's stream sockets.
7373
if (false === stream_socket_get_name($socket, true)) {
74-
return When::reject(new ConnectionException('Connection refused'));
74+
return Promise\reject(new ConnectionException('Connection refused'));
7575
}
7676

77-
return When::resolve($socket);
77+
return Promise\resolve($socket);
7878
}
7979

8080
public function handleConnectedSocket($socket)
@@ -94,7 +94,7 @@ protected function getSocketUrl($host, $port)
9494
protected function resolveHostname($host)
9595
{
9696
if (false !== filter_var($host, FILTER_VALIDATE_IP)) {
97-
return When::resolve($host);
97+
return Promise\resolve($host);
9898
}
9999

100100
return $this->resolver->resolve($host);

src/React/SocketClient/SecureConnector.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use React\EventLoop\LoopInterface;
66
use React\Stream\Stream;
7-
use React\Promise\When;
87

98
class SecureConnector implements ConnectorInterface
109
{

0 commit comments

Comments
 (0)