Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use reactphp/async instead of clue/reactphp-block #77

Merged
merged 1 commit into from Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 13 additions & 9 deletions README.md
Expand Up @@ -154,21 +154,20 @@ If this looks strange to you, you can also use the more traditional [blocking AP

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

If, however, you want to integrate this into your traditional, blocking environment,
you should look into also using [clue/reactphp-block](https://github.com/clue/reactphp-block).

The resulting blocking code could look something like this:
You can also integrate this into your traditional, blocking environment by using
[reactphp/async](https://github.com/reactphp/async). This allows you to simply
await commands on the client like this:

```php
use Clue\React\Block;
use function React\Async\await;

$client = new Clue\React\Docker\Client();

$promise = $client->imageInspect('busybox');

try {
$results = Block\await($promise, Loop::get());
// resporesults successfully received
$results = await($promise);
// results successfully received
} catch (Exception $e) {
// an error occured while performing the request
}
Expand All @@ -177,15 +176,20 @@ try {
Similarly, you can also process multiple commands concurrently and await an array of results:

```php
use function React\Async\await;
dinooo13 marked this conversation as resolved.
Show resolved Hide resolved
use function React\Promise\all;

$promises = array(
$client->imageInspect('busybox'),
$client->imageInspect('ubuntu'),
);

$inspections = Block\awaitAll($promises, Loop::get());
$inspections = await(all($promises));
```

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

#### Command streaming

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -28,7 +28,7 @@
"rize/uri-template": "^0.3"
},
"require-dev": {
"clue/block-react": "^1.5",
"react/async": "^4 || ^3 || ^2",
"clue/caret-notation": "^0.2",
"clue/tar-react": "^0.2",
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
Expand Down