mirror of
https://github.com/amphp/parallel.git
synced 2025-01-17 20:58:36 +01:00
Update example (#140)
This commit is contained in:
parent
7fde6f1308
commit
09ef95a138
@ -30,8 +30,9 @@ The basic usage of this library is to submit blocking tasks to be executed by a
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Amp\Future;
|
||||
use Amp\Parallel\Worker;
|
||||
use Amp\Promise;
|
||||
use function Amp\launch;
|
||||
|
||||
$urls = [
|
||||
'https://secure.php.net',
|
||||
@ -39,12 +40,12 @@ $urls = [
|
||||
'https://github.com',
|
||||
];
|
||||
|
||||
$promises = [];
|
||||
$futures = [];
|
||||
foreach ($urls as $url) {
|
||||
$promises[$url] = Worker\enqueueCallable('file_get_contents', $url);
|
||||
$futures[$url] = launch(fn () => Worker\enqueueCallable('file_get_contents', $url));
|
||||
}
|
||||
|
||||
$responses = Promise\wait(Promise\all($promises));
|
||||
$responses = Future\all($futures);
|
||||
|
||||
foreach ($responses as $url => $response) {
|
||||
\printf("Read %d bytes from %s\n", \strlen($response), $url);
|
||||
|
Loading…
x
Reference in New Issue
Block a user