Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converted coroutines to futures #36

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ root = true
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = spaces
indent_style = space
charset = utf-8
59 changes: 59 additions & 0 deletions .github/workflows/Tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Tests

on:
push:
pull_request:
workflow_dispatch:

jobs:
Test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php:
- 8.1
dependencies:
- hi
- lo

steps:
- uses: actions/checkout@v3

- name: Install Beanstalk
run: sudo apt-get install --yes beanstalkd

- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug

- name: Validate composer.json
run: composer validate

- name: Cache dependencies
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: php-${{ matrix.php }}-${{ matrix.dependencies }}-${{ hashFiles('composer.json') }}
restore-keys: php-${{ matrix.php }}-${{ matrix.dependencies }}-

- name: Install dependencies ${{ matrix.dependencies == 'lo' && '(lowest)' || '' }}
run: composer update --no-interaction --no-progress
${{ matrix.dependencies == 'lo' && '--prefer-lowest' || '' }}

- name: Run test suite with coverage
run: composer test -- --coverage-clover=build/logs/clover.xml
env:
AMP_TEST_BEANSTALK_INTEGRATION: 1

- name: Check code style
run: composer cs

- name: Upload test coverage
run: composer global require php-coveralls/php-coveralls && php-coveralls -v
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/.*/
!/.github/
/coverage/
/composer.lock
/vendor/
/protocol.txt
/.php_cs.cache
/.php-cs-fixer.cache
.phpunit.result.cache
7 changes: 3 additions & 4 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
<?php

return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config)
->setRiskyAllowed(true)
->setRules([
"@PSR1" => true,
"@PSR2" => true,
"braces" => [
"allow_single_line_closure" => true,
"position_after_functions_and_oop_constructs" => "same",
],
"array_syntax" => ["syntax" => "short"],
"cast_spaces" => true,
"combine_consecutive_unsets" => true,
"function_to_constant" => true,
"no_multiline_whitespace_before_semicolons" => true,
"multiline_whitespace_before_semicolons" => true,
"no_unused_imports" => true,
"no_useless_else" => true,
"no_useless_return" => true,
Expand All @@ -27,7 +26,7 @@
"php_unit_fqcn_annotation" => true,
"phpdoc_summary" => true,
"phpdoc_types" => true,
"psr4" => true,
"psr_autoloading" => true,
"return_type_declaration" => ["space_before" => "none"],
"short_scalar_cast" => true,
"single_blank_line_before_namespace" => true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use our shared config in amphp/php-cs-fixer-config:^2, see https://github.com/amphp/amp/blob/d048ec1d03d47fc313d630e989b7a73053f10fae/.php-cs-fixer.dist.php

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be that as it may, I do not think this issue needs to hold up this PR, nor even the 1.0 release, since styles can just be fixed after the fact.

Expand Down
33 changes: 0 additions & 33 deletions .travis.yml

This file was deleted.

23 changes: 14 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,25 @@
"Amp\\Beanstalk\\": "src"
}
},
"minimum-stability": "beta",
"prefer-stable": true,
"require": {
"amphp/amp": "^2",
"amphp/socket": "^1.0",
"amphp/uri": "^0.1",
"php": "^8.1",
"amphp/amp": "^v3.0.0-beta.9",
"amphp/socket": "^v2.0.0-beta.6",
"amphp/uri": "^0.1.4",
"symfony/yaml": "^3.3|^4|^5"
},
"require-dev": {
"amphp/phpunit-util": "^1",
"phpunit/phpunit": "^6",
"friendsofphp/php-cs-fixer": "^2.3"
"amphp/phpunit-util": "^v3.0.0-beta.3",
"friendsofphp/php-cs-fixer": "^3.12",
"phpunit/phpunit": "^9.5.23"
},
"scripts": {
"test": "phpunit",
"cs": "php-cs-fixer fix --dry-run --diff --verbose"
},
"config": {
"platform": {
"php": "7.1.0"
}
"sort-packages": true
}
}
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
*/
Comment on lines +10 to +12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't need such comments any longer, because we use proper types instead of generics inside promises.

$systemStats = $beanstalk->getSystemStats();
echo "Active connections: $systemStats->currentConnections\n";
echo "Jobs ready: $systemStats->currentJobsReady\n";

$beanstalk->quit();
});
$beanstalk->quit();
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="./vendor/autoload.php" colors="true">
<phpunit colors="true">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this now automatically included?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recall a time when it was not. PHPUnit should be launched with bin/phpunit. If you invoke it correctly, it will always include the autoloader. Perhaps if you're one of these people that thinks installing PHPUnit as a global PHAR is a good idea then it might not, but even that is probably no longer the case these days.

<testsuites>
<testsuite name="Tests">
<directory>./test</directory>
Expand Down
3 changes: 2 additions & 1 deletion src/BadFormatException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

namespace Amp\Beanstalk;

class BadFormatException extends BeanstalkException {
class BadFormatException extends BeanstalkException
{
}
Loading