Skip to content

Commit

Permalink
Initial code commit
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Jun 25, 2020
1 parent 0768b75 commit 41751d4
Show file tree
Hide file tree
Showing 22 changed files with 7,365 additions and 2 deletions.
13 changes: 13 additions & 0 deletions .dependabot/config.yml
@@ -0,0 +1,13 @@
version: 1
update_configs:
- package_manager: "php:composer"
directory: "/"
update_schedule: "live"
default_labels:
- "Dependencies 📦"
- "PHP 🐘"
version_requirement_updates: "widen_ranges"
automerged_updates:
- match:
dependency_type: "all"
update_type: "semver:minor"
6 changes: 6 additions & 0 deletions .gitattributes
@@ -0,0 +1,6 @@
.travis.yml export-ignore
.gitignore export-ignore
.gitattributes export-ignore
.scrutinizer.yml export-ignore
phpunit.xml.dist export-ignore
Makefile export-ignore
1 change: 1 addition & 0 deletions .github/FUNDING.yml
@@ -0,0 +1 @@
github: WyriHaximus
47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,47 @@
name: Continuous Integration
on:
push:
pull_request:
jobs:
composer-install:
strategy:
matrix:
php: [7.4]
composer: [lowest, current, highest]
runs-on: ubuntu-latest
container:
image: wyrihaximusnet/php:${{ matrix.php }}-zts-alpine3.10-dev-root
steps:
- uses: actions/checkout@v1
- name: Cache composer packages
uses: actions/cache@v1
with:
path: ./vendor/
key: ${{ matrix.composer }}-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
- name: Install Dependencies
run: composer update --prefer-lowest --no-progress --ansi --no-interaction --prefer-dist
if: matrix.composer == 'lowest'
- name: Install Dependencies
run: composer install --ansi --no-progress --no-interaction --prefer-dist
if: matrix.composer == 'current'
- name: Install Dependencies
run: composer update --ansi --no-progress --no-interaction --prefer-dist
if: matrix.composer == 'highest'
qa:
strategy:
matrix:
php: [7.4]
composer: [lowest, current, highest]
qa: [lint, cs, stan, psalm, unit-ci, infection, composer-require-checker, composer-unused]
needs: composer-install
runs-on: ubuntu-latest
container:
image: wyrihaximusnet/php:${{ matrix.php }}-zts-alpine3.10-dev-root
steps:
- uses: actions/checkout@v1
- name: Cache composer packages
uses: actions/cache@v1
with:
path: ./vendor/
key: ${{ matrix.composer }}-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
- run: make ${{ matrix.qa }}
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
vendor
24 changes: 24 additions & 0 deletions .php_cs
@@ -0,0 +1,24 @@
<?php declare(strict_types=1);

use WyriHaximus\CsFixerConfig\PhpCsFixerConfig;
use PhpCsFixer\Config;

return (function (): Config
{
$paths = [
__DIR__ . DIRECTORY_SEPARATOR . 'src',
__DIR__ . DIRECTORY_SEPARATOR . 'tests',
];

return PhpCsFixerConfig::create()
->setFinder(
PhpCsFixer\Finder::create()
->in($paths)
->append($paths)
)
->setUsingCache(false)
->setRules([
'native_function_invocation' => false,
])
;
})();
1 change: 1 addition & 0 deletions .phpunit.result.cache
@@ -0,0 +1 @@
C:37:"PHPUnit\Runner\DefaultTestResultCache":334:{a:2:{s:7:"defects";a:0:{}s:5:"times";a:4:{s:55:"ReactParallel\Tests\Runtime\RuntimeTest::convertSuccess";d:3.039;s:55:"ReactParallel\Tests\Runtime\RuntimeTest::convertFailure";d:3.029;s:58:"ReactParallel\Tests\Runtime\RuntimeTest::weClosedTheThread";d:1.004;s:58:"ReactParallel\Tests\Runtime\RuntimeTest::weKilledTheThread";d:1.005;}}}
68 changes: 68 additions & 0 deletions .scrutinizer.yml
@@ -0,0 +1,68 @@
filter:
paths: [src/*]
excluded_paths: [tests/* examples/*]
tools:
external_code_coverage: true
php_analyzer: true
php_hhvm: true
php_sim: true
php_pdepend: true
sensiolabs_security_checker: true
php_changetracking: true
php_code_sniffer:
enabled: true
config:
tab_width: 0
encoding: utf8
ruleset: ~
standard: "PSR2"
php_cs_fixer:
enabled: true
config:
level: psr2
php_mess_detector:
enabled: true
config:
ruleset: ~
code_size_rules:
cyclomatic_complexity: true
npath_complexity: true
excessive_method_length: true
excessive_class_length: true
excessive_parameter_list: true
excessive_public_count: true
too_many_fields: true
too_many_methods: true
excessive_class_complexity: true
design_rules:
exit_expression: true
eval_expression: true
goto_statement: true
number_of_class_children: true
depth_of_inheritance: true
coupling_between_objects: true
unused_code_rules:
unused_private_field: true
unused_local_variable: true
unused_private_method: true
unused_formal_parameter: true
naming_rules:
short_variable:
minimum: 3
long_variable:
maximum: 20
short_method:
minimum: 3
constructor_conflict: true
constant_naming: true
boolean_method_name: true
controversial_rules:
superglobals: true
camel_case_class_name: true
camel_case_property_name: true
camel_case_method_name: true
camel_case_parameter_name: true
camel_case_variable_name: true
checks:
php:
code_rating: true
45 changes: 45 additions & 0 deletions Makefile
@@ -0,0 +1,45 @@
# set all to phony
SHELL=bash

.PHONY: *

ifneq ("$(wildcard /.dockerenv)","")
DOCKER_RUN=
else
DOCKER_RUN=docker run --rm -it \
-v `pwd`:`pwd` \
-w `pwd` \
"wyrihaximusnet/php:7.4-zts-alpine3.11-dev"
endif

all: lint cs-fix cs stan psalm unit infection composer-require-checker composer-unused

lint:
$(DOCKER_RUN) vendor/bin/parallel-lint --exclude vendor .

cs:
$(DOCKER_RUN) vendor/bin/phpcs --parallel=$(nproc)

cs-fix:
$(DOCKER_RUN) vendor/bin/phpcbf --parallel=$(nproc)

stan:
$(DOCKER_RUN) vendor/bin/phpstan analyse src tests --level max --ansi -c phpstan.neon

psalm:
$(DOCKER_RUN) vendor/bin/psalm --threads=$(nproc) --shepherd --stats

unit:
$(DOCKER_RUN) vendor/bin/phpunit --colors=always -c phpunit.xml.dist --coverage-text --coverage-html covHtml --coverage-clover ./build/logs/clover.xml

unit-ci: unit
if [ -f ./build/logs/clover.xml ]; then wget https://scrutinizer-ci.com/ocular.phar && sleep 3 && php ocular.phar code-coverage:upload --format=php-clover ./build/logs/clover.xml; fi

infection:
$(DOCKER_RUN) vendor/bin/infection --ansi --min-msi=100 --min-covered-msi=100 --threads=$(nproc)

composer-require-checker:
$(DOCKER_RUN) vendor/bin/composer-require-checker --ignore-parse-errors --ansi -vvv --config-file=composer-require-checker.json

composer-unused:
$(DOCKER_RUN) composer unused --ansi
117 changes: 115 additions & 2 deletions README.md
@@ -1,2 +1,115 @@
# event-loop
Event Loop bridge to ext-parallel Events
# Event Loop bridge to ext-parallel Events

![Continuous Integration](https://github.com/Reactphp-parallel/event-loop/workflows/Continuous%20Integration/badge.svg)
[![Latest Stable Version](https://poser.pugx.org/React-parallel/event-loop/v/stable.png)](https://packagist.org/packages/React-parallel/event-loop)
[![Total Downloads](https://poser.pugx.org/React-parallel/event-loop/downloads.png)](https://packagist.org/packages/React-parallel/event-loop)
[![Code Coverage](https://scrutinizer-ci.com/g/Reactphp-parallel/event-loop/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Reactphp-parallel/event-loop/?branch=master)
[![Type Coverage](https://shepherd.dev/github/Reactphp-parallel/event-loop/coverage.svg)](https://shepherd.dev/github/Reactphp-parallel/event-loop)
[![License](https://poser.pugx.org/React-parallel/event-loop/license.png)](https://packagist.org/packages/React-parallel/event-loop)

### Installation ###

To install via [Composer](http://getcomposer.org/), use the command below, it will automatically detect the latest version and bind it with `~`.

```
composer require react-parallel/event-loop
```

# Usage

## Set up

Just like the ReactPHP event loop, you should only have one bridge. You can have multiple, and unlike the ReactPHP
event loop, that will work, but it adds additional overhead when you have more than a few. Having a hand full for
different major contexts. Share this bridge around so that other packages can use them, and only have one instance
checking for events.

```php
use React\EventLoop\Factory;
use ReactParallel\EventLoop\EventLoopBridge;

$loop = Factory::create();
$eventLoopBridge = new EventLoopBridge($loop);

$loop->run();
```

## Channels

Channels often have a stream of messages going over them, as such the bridge will convert them into an observable.

```php
use parallel\Channel;
use React\EventLoop\Factory;
use ReactParallel\EventLoop\EventLoopBridge;

$loop = Factory::create();
$eventLoopBridge = new EventLoopBridge($loop);

$channel = new Channel(Channel::Infinite);
$eventLoopBridge->observe($channel)->subscribe(function (string $message) {
echo $message, PHP_EOL;
});

$loop->futureTick(function () use ($channel): void {
$channel->send('Hello World!');
$channel->close();
});

$loop->run();
```

## Futures

Where promises are push, futures are pull, as such the event loop will poll and resolve the promise once a result is
available.

```php
use parallel\Channel;
use React\EventLoop\Factory;
use ReactParallel\EventLoop\EventLoopBridge;
use function parallel\run;

$loop = Factory::create();
$eventLoopBridge = new EventLoopBridge($loop);

$future = run(function (): string {
return 'Hello World!';
});

$channel = new Channel(Channel::Infinite);
$eventLoopBridge->await($future)->then(function (string $message) {
echo $message, PHP_EOL;
});

$loop->run();
```

## Contributing ##

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

## License ##

Copyright 2020 [Cees-Jan Kiewiet](http://wyrihaximus.net/)

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
19 changes: 19 additions & 0 deletions composer-require-checker.json
@@ -0,0 +1,19 @@
{
"symbol-whitelist" : [
"null", "true", "false",
"static", "self", "parent",
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object",
"WyriHaximus\\Constants\\ComposerAutoloader\\LOCATION", "WyriHaximus\\Constants\\Boolean\\FALSE_",
"WyriHaximus\\Constants\\Boolean\\TRUE_", "WyriHaximus\\Constants\\Numeric\\ZERO"
],
"php-core-extensions" : [
"Core",
"date",
"pcre",
"Phar",
"Reflection",
"SPL",
"standard"
],
"scan-files" : []
}

0 comments on commit 41751d4

Please sign in to comment.