Skip to content

Commit

Permalink
Updated examples to be Amp v3 (fibers) compliant.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilge committed Oct 18, 2022
1 parent 36ae23c commit cb1dba7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 34 deletions.
17 changes: 7 additions & 10 deletions examples/consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
require __DIR__ . '/../vendor/autoload.php';

use Amp\Beanstalk\BeanstalkClient;
use Amp\Loop;

Loop::run(function () {
$beanstalk = new BeanstalkClient("tcp://127.0.0.1:11300");
yield $beanstalk->watch('foobar');
$beanstalk = new BeanstalkClient('tcp://127.0.0.1:11300');
$beanstalk->watch('foobar');

while (list($jobId, $payload) = yield $beanstalk->reserve()) {
echo "Job id: $jobId\n";
echo "Payload: $payload\n";
while (list($jobId, $payload) = $beanstalk->reserve()) {
echo "Job id: $jobId\n";
echo "Payload: $payload\n";

$beanstalk->delete($jobId);
}
});
$beanstalk->delete($jobId);
}
23 changes: 10 additions & 13 deletions examples/producer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@
require __DIR__ . '/../vendor/autoload.php';

use Amp\Beanstalk\BeanstalkClient;
use Amp\Loop;

Loop::run(function () {
$beanstalk = new BeanstalkClient("tcp://127.0.0.1:11300");
yield $beanstalk->use('foobar');
$beanstalk = new BeanstalkClient('tcp://127.0.0.1:11300');
$beanstalk->use('foobar');

$payload = json_encode([
"job" => bin2hex(random_bytes(16)),
"type" => "compress-image",
"path" => "/path/to/image.png"
]);
$payload = json_encode([
'job' => bin2hex(random_bytes(16)),
'type' => 'compress-image',
'path' => '/path/to/image.png'
]);

$jobId = yield $beanstalk->put($payload);
$jobId = $beanstalk->put($payload);

echo "Inserted job id: $jobId\n";
echo "Inserted job id: $jobId\n";

$beanstalk->quit();
});
$beanstalk->quit();
19 changes: 8 additions & 11 deletions examples/stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@

use Amp\Beanstalk\BeanstalkClient;
use Amp\Beanstalk\Stats\System;
use Amp\Loop;

Loop::run(function () {
$beanstalk = new BeanstalkClient("tcp://127.0.0.1:11300");
$beanstalk = new BeanstalkClient('tcp://127.0.0.1:11300');

/**
* @var System $systemStats
*/
$systemStats = yield $beanstalk->getSystemStats();
echo "Active connections: {$systemStats->currentConnections}\n";
echo "Jobs ready: {$systemStats->currentJobsReady}\n";
/**
* @var System $systemStats
*/
$systemStats = $beanstalk->getSystemStats();
echo "Active connections: $systemStats->currentConnections\n";
echo "Jobs ready: $systemStats->currentJobsReady\n";

$beanstalk->quit();
});
$beanstalk->quit();

0 comments on commit cb1dba7

Please sign in to comment.