Skip to content

Commit

Permalink
Merge 6109e9f into f56e461
Browse files Browse the repository at this point in the history
  • Loading branch information
PeeHaa committed Nov 8, 2018
2 parents f56e461 + 6109e9f commit b46e8ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions examples/worker-pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

// We can first define tasks and then run them
$tasks = [
new CallableTask('file_get_contents', 'http://php.net'),
new CallableTask('file_get_contents', 'https://amphp.org'),
new CallableTask('file_get_contents', 'https://github.com'),
new CallableTask('file_get_contents', ['http://php.net']),
new CallableTask('file_get_contents', ['https://amphp.org']),
new CallableTask('file_get_contents', ['https://github.com']),
];

// Event loop for parallel tasks
Expand All @@ -28,11 +28,10 @@

$coroutines = [];

foreach ($tasks as $task) {
$coroutines[] = Amp\call(function () use ($pool, $task) {
foreach ($tasks as $index => $task) {
$coroutines[] = Amp\call(function () use ($pool, $index, $task) {
$result = yield $pool->enqueue($task);
$url = $task->getArgs()[0];
\printf("\nRead from %s: %d bytes\n", $url, \strlen($result));
\printf("\nRead from task %d: %d bytes\n", $index, \strlen($result));
return $result;
});
}
Expand Down
2 changes: 1 addition & 1 deletion examples/worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

$worker = $factory->create();

$result = yield $worker->enqueue(new CallableTask('file_get_contents', 'https://google.com'));
$result = yield $worker->enqueue(new CallableTask('file_get_contents', ['https://google.com']));
\printf("Read %d bytes\n", \strlen($result));

$code = yield $worker->shutdown();
Expand Down

0 comments on commit b46e8ab

Please sign in to comment.