Skip to content

Commit b4ea252

Browse files
committed
Update to use new reactphp/async package instead of clue/reactphp-block
1 parent d9cb7fc commit b4ea252

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

README.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -422,15 +422,13 @@ $promise = Queue::any(10, $jobs, array($browser, 'get'));
422422
#### Blocking
423423

424424
As stated above, this library provides you a powerful, async API by default.
425-
If, however, you want to integrate this into your traditional, blocking
426-
environment, you may want to look into also using
427-
[clue/reactphp-block](https://github.com/clue/reactphp-block).
428425

429-
The resulting blocking code that awaits a number of concurrent HTTP requests
430-
could look something like this:
426+
You can also integrate this into your traditional, blocking environment by using
427+
[reactphp/async](https://github.com/reactphp/async). This allows you to simply
428+
await async HTTP requests like this:
431429

432430
```php
433-
use Clue\React\Block;
431+
use function React\Async\await;
434432

435433
$browser = new React\Http\Browser();
436434

@@ -439,7 +437,7 @@ $promise = Queue::all(3, $urls, function ($url) use ($browser) {
439437
});
440438

441439
try {
442-
$responses = Block\await($promise, $loop);
440+
$responses = await($promise);
443441
// responses successfully received
444442
} catch (Exception $e) {
445443
// an error occured while performing the requests
@@ -450,6 +448,8 @@ Similarly, you can also wrap this in a function to provide a simple API and hide
450448
all the async details from the outside:
451449

452450
```php
451+
use function React\Async\await;
452+
453453
/**
454454
* Concurrently downloads all the given URIs
455455
*
@@ -465,12 +465,13 @@ function download(array $uris)
465465
return $browser->get($uri);
466466
});
467467

468-
return Clue\React\Block\await($promise, $loop);
468+
return await($promise);
469469
}
470470
```
471471

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

475476
> Keep in mind that returning an array of response messages means that the whole
476477
response body has to be kept in memory.

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"react/promise": "^3 || ^2.2.1 || ^1.2.1"
2222
},
2323
"require-dev": {
24-
"clue/block-react": "^1.5",
2524
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35",
25+
"react/async": "^4 || ^3 || ^2",
2626
"react/event-loop": "^1.2",
2727
"react/http": "^1.8"
2828
}

examples/11-http-blocking.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<?php
22

3-
use Clue\React\Block;
4-
use React\EventLoop\Loop;
5-
63
require __DIR__ . '/../vendor/autoload.php';
74

85
// list of all URLs you want to download
@@ -33,7 +30,7 @@ function (Exception $e) {
3330
);
3431
});
3532

36-
return Block\await($promise, Loop::get());
33+
return React\Async\await($promise);
3734
}
3835

3936
$responses = download($urls);

0 commit comments

Comments
 (0)