@@ -422,15 +422,13 @@ $promise = Queue::any(10, $jobs, array($browser, 'get'));
422
422
#### Blocking
423
423
424
424
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 ) .
428
425
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:
431
429
432
430
``` php
433
- use Clue\ React\Block ;
431
+ use function React\Async\await ;
434
432
435
433
$browser = new React\Http\Browser();
436
434
@@ -439,7 +437,7 @@ $promise = Queue::all(3, $urls, function ($url) use ($browser) {
439
437
});
440
438
441
439
try {
442
- $responses = Block\ await($promise, $loop );
440
+ $responses = await($promise);
443
441
// responses successfully received
444
442
} catch (Exception $e) {
445
443
// 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
450
448
all the async details from the outside:
451
449
452
450
``` php
451
+ use function React\Async\await;
452
+
453
453
/**
454
454
* Concurrently downloads all the given URIs
455
455
*
@@ -465,12 +465,13 @@ function download(array $uris)
465
465
return $browser->get($uri);
466
466
});
467
467
468
- return Clue\React\Block\ await($promise, $loop );
468
+ return await($promise);
469
469
}
470
470
```
471
471
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.
474
475
475
476
> Keep in mind that returning an array of response messages means that the whole
476
477
response body has to be kept in memory.
0 commit comments