@@ -422,15 +422,12 @@ $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
-
429
- The resulting blocking code that awaits a number of concurrent HTTP requests
430
- could look something like this:
425
+ You can also integrate this into your traditional, blocking environment by using
426
+ [ reactphp/async] ( https://github.com/reactphp/async ) . This allows you to simply
427
+ await async HTTP requests like this:
431
428
432
429
``` php
433
- use Clue\ React\Block ;
430
+ use function React\Async\await ;
434
431
435
432
$browser = new React\Http\Browser();
436
433
@@ -439,7 +436,7 @@ $promise = Queue::all(3, $urls, function ($url) use ($browser) {
439
436
});
440
437
441
438
try {
442
- $responses = Block\ await($promise, $loop );
439
+ $responses = await($promise);
443
440
// responses successfully received
444
441
} catch (Exception $e) {
445
442
// an error occured while performing the requests
@@ -450,6 +447,8 @@ Similarly, you can also wrap this in a function to provide a simple API and hide
450
447
all the async details from the outside:
451
448
452
449
``` php
450
+ use function React\Async\await;
451
+
453
452
/**
454
453
* Concurrently downloads all the given URIs
455
454
*
@@ -465,12 +464,13 @@ function download(array $uris)
465
464
return $browser->get($uri);
466
465
});
467
466
468
- return Clue\React\Block\ await($promise, $loop );
467
+ return await($promise);
469
468
}
470
469
```
471
470
472
- Please refer to [ clue/reactphp-block] ( https://github.com/clue/reactphp-block#readme )
473
- for more details.
471
+ This is made possible thanks to fibers available in PHP 8.1+ and our
472
+ compatibility API that also works on all supported PHP versions.
473
+ Please refer to [ reactphp/async] ( https://github.com/reactphp/async#readme ) for more details.
474
474
475
475
> Keep in mind that returning an array of response messages means that the whole
476
476
response body has to be kept in memory.
0 commit comments