Skip to content

Commit b5a66a4

Browse files
authored
Merge pull request #464 from clue-labs/async
Update test suite to use new reactphp/async package instead of clue/reactphp-block
2 parents b3ff9c8 + 9946ba7 commit b5a66a4

11 files changed

+165
-129
lines changed

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -373,20 +373,19 @@ See also [`withFollowRedirects()`](#withfollowredirects) for more details.
373373

374374
As stated above, this library provides you a powerful, async API by default.
375375

376-
If, however, you want to integrate this into your traditional, blocking environment,
377-
you should look into also using [clue/reactphp-block](https://github.com/clue/reactphp-block).
378-
379-
The resulting blocking code could look something like this:
376+
You can also integrate this into your traditional, blocking environment by using
377+
[reactphp/async](https://github.com/reactphp/async). This allows you to simply
378+
await async HTTP requests like this:
380379

381380
```php
382-
use Clue\React\Block;
381+
use function React\Async\await;
383382

384383
$browser = new React\Http\Browser();
385384

386385
$promise = $browser->get('http://example.com/');
387386

388387
try {
389-
$response = Block\await($promise, Loop::get());
388+
$response = await($promise);
390389
// response successfully received
391390
} catch (Exception $e) {
392391
// an error occurred while performing the request
@@ -396,15 +395,20 @@ try {
396395
Similarly, you can also process multiple requests concurrently and await an array of `Response` objects:
397396

398397
```php
398+
use function React\Async\await;
399+
use function React\Promise\all;
400+
399401
$promises = array(
400402
$browser->get('http://example.com/'),
401403
$browser->get('http://www.example.org/'),
402404
);
403405

404-
$responses = Block\awaitAll($promises, Loop::get());
406+
$responses = await(all($promises));
405407
```
406408

407-
Please refer to [clue/reactphp-block](https://github.com/clue/reactphp-block#readme) for more details.
409+
This is made possible thanks to fibers available in PHP 8.1+ and our
410+
compatibility API that also works on all supported PHP versions.
411+
Please refer to [reactphp/async](https://github.com/reactphp/async#readme) for more details.
408412

409413
Keep in mind the above remark about buffering the whole response message in memory.
410414
As an alternative, you may also see one of the following chapters for the

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@
3838
"ringcentral/psr7": "^1.2"
3939
},
4040
"require-dev": {
41-
"clue/block-react": "^1.5",
4241
"clue/http-proxy-react": "^1.7",
4342
"clue/reactphp-ssh-proxy": "^1.3",
4443
"clue/socks-react": "^1.3",
45-
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
44+
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35",
45+
"react/async": "^4 || ^3 || ^2",
46+
"react/promise-timer": "^1.9"
4647
},
4748
"autoload": {
4849
"psr-4": { "React\\Http\\": "src" }

tests/BrowserTest.php

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

33
namespace React\Tests\Http;
44

5-
use Clue\React\Block;
65
use Psr\Http\Message\RequestInterface;
76
use React\Http\Browser;
87
use React\Promise\Promise;

tests/Client/FunctionalIntegrationTest.php

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

33
namespace React\Tests\Http\Client;
44

5-
use Clue\React\Block;
65
use Psr\Http\Message\ResponseInterface;
76
use React\EventLoop\Loop;
87
use React\Http\Client\Client;
@@ -51,7 +50,7 @@ public function testRequestToLocalhostEmitsSingleRemoteConnection()
5150
$promise = Stream\first($request, 'close');
5251
$request->end();
5352

54-
Block\await($promise, null, self::TIMEOUT_LOCAL);
53+
\React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT_LOCAL));
5554
}
5655

5756
public function testRequestLegacyHttpServerWithOnlyLineFeedReturnsSuccessfulResponse()
@@ -73,7 +72,7 @@ public function testRequestLegacyHttpServerWithOnlyLineFeedReturnsSuccessfulResp
7372
$promise = Stream\first($request, 'close');
7473
$request->end();
7574

76-
Block\await($promise, null, self::TIMEOUT_LOCAL);
75+
\React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT_LOCAL));
7776
}
7877

7978
/** @group internet */
@@ -94,7 +93,7 @@ public function testSuccessfulResponseEmitsEnd()
9493
$promise = Stream\first($request, 'close');
9594
$request->end();
9695

97-
Block\await($promise, null, self::TIMEOUT_REMOTE);
96+
\React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT_REMOTE));
9897
}
9998

10099
/** @group internet */
@@ -122,7 +121,7 @@ public function testPostDataReturnsData()
122121

123122
$request->end($data);
124123

125-
$buffer = Block\await($deferred->promise(), null, self::TIMEOUT_REMOTE);
124+
$buffer = \React\Async\await(\React\Promise\Timer\timeout($deferred->promise(), self::TIMEOUT_REMOTE));
126125

127126
$this->assertNotEquals('', $buffer);
128127

@@ -154,7 +153,7 @@ public function testPostJsonReturnsData()
154153

155154
$request->end($data);
156155

157-
$buffer = Block\await($deferred->promise(), null, self::TIMEOUT_REMOTE);
156+
$buffer = \React\Async\await(\React\Promise\Timer\timeout($deferred->promise(), self::TIMEOUT_REMOTE));
158157

159158
$this->assertNotEquals('', $buffer);
160159

0 commit comments

Comments
 (0)