1
0
mirror of https://github.com/danog/loop.git synced 2024-11-26 20:04:44 +01:00

Github actions

This commit is contained in:
Daniil Gentili 2020-07-23 14:18:33 +02:00
parent cecf4c1a07
commit 59a9cd54d2
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
5 changed files with 78 additions and 7 deletions

42
.github/workflows/build.yaml vendored Normal file
View File

@ -0,0 +1,42 @@
name: build
on:
pull_request:
push:
jobs:
run:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest, macos-latest]
php-versions: ['7.1', '7.2', '7.3', '7.4']
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl
coverage: xdebug
- name: Check environment
run: |
php --version
composer --version
- name: Install dependencies
run: composer update -n --prefer-dist
- name: Run tests
run: |
vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml
PHP_CS_FIXER_IGNORE_ENV=1 php vendor/bin/php-cs-fixer --diff --dry-run -v fix
vendor/bin/psalm
- name: Collect code coverage
env:
COVERALLS_REPO_TOKEN: ${{secrets.GITHUB_TOKEN}}
if: success()
run: vendor/bin/coveralls build/logs/clover.xml

View File

@ -24,7 +24,8 @@
"phpunit/phpunit": "^7 | ^8 | ^9",
"amphp/phpunit-util": "^1.3",
"amphp/php-cs-fixer-config": "dev-master",
"vimeo/psalm": "dev-master"
"vimeo/psalm": "dev-master",
"cedx/coveralls": "^13.2"
},
"autoload": {
"psr-4": {

View File

@ -0,0 +1,30 @@
<?php
require 'vendor/autoload.php';
use Amp\Loop;
use danog\Loop\Generic\GenericLoop;
use function Amp\delay;
Loop::run(function () {
/** @var GenericLoop[] */
$loops = [];
for ($x = 0; $x < 10; $x++) {
$loop = new GenericLoop("Loop number $x");
$loop->start();
yield delay(100);
$loops []= $loop;
}
yield delay(5000);
echo "Resuming prematurely all loops!".PHP_EOL;
foreach ($loops as $loop) {
$loop->resume();
}
echo "OK done, waiting 5 more seconds!".PHP_EOL;
yield delay(5000);
echo "Closing all loops!".PHP_EOL;
foreach ($loops as $loop) {
$loop->signal(true);
}
});

View File

@ -86,19 +86,18 @@ class GenericLoop extends ResumableSignalLoop
{
$callable = $this->callable;
while (true) {
/** @psalm-var TCallable */
/** @psalm-var ?int|TGenerator|TPromise */
$timeout = $callable();
if ($timeout instanceof \Generator) {
/** @psalm-var TGenerator */
/** @psalm-var ?int */
$timeout = yield from $timeout;
} elseif ($timeout instanceof Promise) {
/** @psalm-var TPromise */
/** @psalm-var ?int */
$timeout = yield $timeout;
}
if ($timeout === self::PAUSE) {
$this->reportPause(0);
} elseif ($timeout > 0) {
/** @psalm-suppress MixedArgument */
$this->reportPause($timeout);
}
/** @psalm-suppress MixedArgument */

View File

@ -74,7 +74,6 @@ class PeriodicLoop extends ResumableSignalLoop
{
$callback = $this->callback;
while (true) {
/** @psalm-suppress MixedAssignment */
$result = $callback();
if ($result instanceof \Generator) {
/** @psalm-var TGenerator */
@ -86,7 +85,7 @@ class PeriodicLoop extends ResumableSignalLoop
if ($result === true) {
return;
}
/** @psalm-suppress MixedAssignment */
/** @var ?bool */
$result = yield $this->waitSignal($this->pause($this->interval));
if ($result === true) {
return;