Skip to content

Commit ecf5644

Browse files
committed
Initial code commit
1 parent 0768b75 commit ecf5644

22 files changed

+7770
-2
lines changed

.dependabot/config.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 1
2+
update_configs:
3+
- package_manager: "php:composer"
4+
directory: "/"
5+
update_schedule: "live"
6+
default_labels:
7+
- "Dependencies 📦"
8+
- "PHP 🐘"
9+
version_requirement_updates: "widen_ranges"
10+
automerged_updates:
11+
- match:
12+
dependency_type: "all"
13+
update_type: "semver:minor"

.gitattributes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.travis.yml export-ignore
2+
.gitignore export-ignore
3+
.gitattributes export-ignore
4+
.scrutinizer.yml export-ignore
5+
phpunit.xml.dist export-ignore
6+
Makefile export-ignore

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: WyriHaximus

.github/workflows/ci.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Continuous Integration
2+
on:
3+
push:
4+
pull_request:
5+
jobs:
6+
composer-install:
7+
strategy:
8+
matrix:
9+
php: [7.4]
10+
composer: [lowest, current, highest]
11+
runs-on: ubuntu-latest
12+
container:
13+
image: wyrihaximusnet/php:${{ matrix.php }}-zts-alpine3.12-dev-root
14+
steps:
15+
- uses: actions/checkout@v1
16+
- name: Cache composer packages
17+
uses: actions/cache@v1
18+
with:
19+
path: ./vendor/
20+
key: ${{ matrix.composer }}-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
21+
- name: Install Dependencies
22+
run: composer update --prefer-lowest --no-progress --ansi --no-interaction --prefer-dist
23+
if: matrix.composer == 'lowest'
24+
- name: Install Dependencies
25+
run: composer install --ansi --no-progress --no-interaction --prefer-dist
26+
if: matrix.composer == 'current'
27+
- name: Install Dependencies
28+
run: composer update --ansi --no-progress --no-interaction --prefer-dist
29+
if: matrix.composer == 'highest'
30+
qa:
31+
strategy:
32+
matrix:
33+
php: [7.4]
34+
composer: [lowest, current, highest]
35+
qa: [lint, cs, stan, psalm, unit-ci, infection, composer-require-checker, composer-unused]
36+
needs: composer-install
37+
runs-on: ubuntu-latest
38+
container:
39+
image: wyrihaximusnet/php:${{ matrix.php }}-zts-alpine3.12-dev-root
40+
steps:
41+
- uses: actions/checkout@v1
42+
- name: Cache composer packages
43+
uses: actions/cache@v1
44+
with:
45+
path: ./vendor/
46+
key: ${{ matrix.composer }}-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
47+
- run: make ${{ matrix.qa }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor

.php_cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php declare(strict_types=1);
2+
3+
use WyriHaximus\CsFixerConfig\PhpCsFixerConfig;
4+
use PhpCsFixer\Config;
5+
6+
return (function (): Config
7+
{
8+
$paths = [
9+
__DIR__ . DIRECTORY_SEPARATOR . 'src',
10+
__DIR__ . DIRECTORY_SEPARATOR . 'tests',
11+
];
12+
13+
return PhpCsFixerConfig::create()
14+
->setFinder(
15+
PhpCsFixer\Finder::create()
16+
->in($paths)
17+
->append($paths)
18+
)
19+
->setUsingCache(false)
20+
->setRules([
21+
'native_function_invocation' => false,
22+
])
23+
;
24+
})();

.phpunit.result.cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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;}}}

.scrutinizer.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
filter:
2+
paths: [src/*]
3+
excluded_paths: [tests/* examples/*]
4+
tools:
5+
external_code_coverage: true
6+
php_analyzer: true
7+
php_hhvm: true
8+
php_sim: true
9+
php_pdepend: true
10+
sensiolabs_security_checker: true
11+
php_changetracking: true
12+
php_code_sniffer:
13+
enabled: true
14+
config:
15+
tab_width: 0
16+
encoding: utf8
17+
ruleset: ~
18+
standard: "PSR2"
19+
php_cs_fixer:
20+
enabled: true
21+
config:
22+
level: psr2
23+
php_mess_detector:
24+
enabled: true
25+
config:
26+
ruleset: ~
27+
code_size_rules:
28+
cyclomatic_complexity: true
29+
npath_complexity: true
30+
excessive_method_length: true
31+
excessive_class_length: true
32+
excessive_parameter_list: true
33+
excessive_public_count: true
34+
too_many_fields: true
35+
too_many_methods: true
36+
excessive_class_complexity: true
37+
design_rules:
38+
exit_expression: true
39+
eval_expression: true
40+
goto_statement: true
41+
number_of_class_children: true
42+
depth_of_inheritance: true
43+
coupling_between_objects: true
44+
unused_code_rules:
45+
unused_private_field: true
46+
unused_local_variable: true
47+
unused_private_method: true
48+
unused_formal_parameter: true
49+
naming_rules:
50+
short_variable:
51+
minimum: 3
52+
long_variable:
53+
maximum: 20
54+
short_method:
55+
minimum: 3
56+
constructor_conflict: true
57+
constant_naming: true
58+
boolean_method_name: true
59+
controversial_rules:
60+
superglobals: true
61+
camel_case_class_name: true
62+
camel_case_property_name: true
63+
camel_case_method_name: true
64+
camel_case_parameter_name: true
65+
camel_case_variable_name: true
66+
checks:
67+
php:
68+
code_rating: true

Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# set all to phony
2+
SHELL=bash
3+
4+
.PHONY: *
5+
6+
ifneq ("$(wildcard /.dockerenv)","")
7+
DOCKER_RUN=
8+
else
9+
DOCKER_RUN=docker run --rm -it \
10+
-v `pwd`:`pwd` \
11+
-w `pwd` \
12+
"wyrihaximusnet/php:7.4-zts-alpine3.11-dev"
13+
endif
14+
15+
all: lint cs-fix cs stan psalm unit infection composer-require-checker composer-unused
16+
17+
lint:
18+
$(DOCKER_RUN) vendor/bin/parallel-lint --exclude vendor .
19+
20+
cs:
21+
$(DOCKER_RUN) vendor/bin/phpcs --parallel=$(nproc)
22+
23+
cs-fix:
24+
$(DOCKER_RUN) vendor/bin/phpcbf --parallel=$(nproc)
25+
26+
stan:
27+
$(DOCKER_RUN) vendor/bin/phpstan analyse src tests --level max --ansi -c phpstan.neon
28+
29+
psalm:
30+
$(DOCKER_RUN) vendor/bin/psalm --threads=$(nproc) --shepherd --stats
31+
32+
unit:
33+
$(DOCKER_RUN) vendor/bin/phpunit --colors=always -c phpunit.xml.dist --coverage-text --coverage-html covHtml --coverage-clover ./build/logs/clover.xml
34+
35+
unit-ci: unit
36+
if [ -f ./build/logs/clover.xml ]; then sleep 3; fi
37+
38+
infection:
39+
$(DOCKER_RUN) vendor/bin/infection --ansi --min-msi=100 --min-covered-msi=100 --threads=$(nproc)
40+
41+
composer-require-checker:
42+
$(DOCKER_RUN) vendor/bin/composer-require-checker --ignore-parse-errors --ansi -vvv --config-file=composer-require-checker.json
43+
44+
composer-unused:
45+
$(DOCKER_RUN) composer unused --ansi

README.md

Lines changed: 115 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,115 @@
1-
# event-loop
2-
Event Loop bridge to ext-parallel Events
1+
# Event Loop bridge to ext-parallel Events
2+
3+
![Continuous Integration](https://github.com/Reactphp-parallel/event-loop/workflows/Continuous%20Integration/badge.svg)
4+
[![Latest Stable Version](https://poser.pugx.org/React-parallel/event-loop/v/stable.png)](https://packagist.org/packages/React-parallel/event-loop)
5+
[![Total Downloads](https://poser.pugx.org/React-parallel/event-loop/downloads.png)](https://packagist.org/packages/React-parallel/event-loop)
6+
[![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)
7+
[![Type Coverage](https://shepherd.dev/github/Reactphp-parallel/event-loop/coverage.svg)](https://shepherd.dev/github/Reactphp-parallel/event-loop)
8+
[![License](https://poser.pugx.org/React-parallel/event-loop/license.png)](https://packagist.org/packages/React-parallel/event-loop)
9+
10+
### Installation ###
11+
12+
To install via [Composer](http://getcomposer.org/), use the command below, it will automatically detect the latest version and bind it with `~`.
13+
14+
```
15+
composer require react-parallel/event-loop
16+
```
17+
18+
# Usage
19+
20+
## Set up
21+
22+
Just like the ReactPHP event loop, you should only have one bridge. You can have multiple, and unlike the ReactPHP
23+
event loop, that will work, but it adds additional overhead when you have more than a few. Having a hand full for
24+
different major contexts. Share this bridge around so that other packages can use them, and only have one instance
25+
checking for events.
26+
27+
```php
28+
use React\EventLoop\Factory;
29+
use ReactParallel\EventLoop\EventLoopBridge;
30+
31+
$loop = Factory::create();
32+
$eventLoopBridge = new EventLoopBridge($loop);
33+
34+
$loop->run();
35+
```
36+
37+
## Channels
38+
39+
Channels often have a stream of messages going over them, as such the bridge will convert them into an observable.
40+
41+
```php
42+
use parallel\Channel;
43+
use React\EventLoop\Factory;
44+
use ReactParallel\EventLoop\EventLoopBridge;
45+
46+
$loop = Factory::create();
47+
$eventLoopBridge = new EventLoopBridge($loop);
48+
49+
$channel = new Channel(Channel::Infinite);
50+
$eventLoopBridge->observe($channel)->subscribe(function (string $message) {
51+
echo $message, PHP_EOL;
52+
});
53+
54+
$loop->futureTick(function () use ($channel): void {
55+
$channel->send('Hello World!');
56+
$channel->close();
57+
});
58+
59+
$loop->run();
60+
```
61+
62+
## Futures
63+
64+
Where promises are push, futures are pull, as such the event loop will poll and resolve the promise once a result is
65+
available.
66+
67+
```php
68+
use parallel\Channel;
69+
use React\EventLoop\Factory;
70+
use ReactParallel\EventLoop\EventLoopBridge;
71+
use function parallel\run;
72+
73+
$loop = Factory::create();
74+
$eventLoopBridge = new EventLoopBridge($loop);
75+
76+
$future = run(function (): string {
77+
return 'Hello World!';
78+
});
79+
80+
$channel = new Channel(Channel::Infinite);
81+
$eventLoopBridge->await($future)->then(function (string $message) {
82+
echo $message, PHP_EOL;
83+
});
84+
85+
$loop->run();
86+
```
87+
88+
## Contributing ##
89+
90+
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
91+
92+
## License ##
93+
94+
Copyright 2020 [Cees-Jan Kiewiet](http://wyrihaximus.net/)
95+
96+
Permission is hereby granted, free of charge, to any person
97+
obtaining a copy of this software and associated documentation
98+
files (the "Software"), to deal in the Software without
99+
restriction, including without limitation the rights to use,
100+
copy, modify, merge, publish, distribute, sublicense, and/or sell
101+
copies of the Software, and to permit persons to whom the
102+
Software is furnished to do so, subject to the following
103+
conditions:
104+
105+
The above copyright notice and this permission notice shall be
106+
included in all copies or substantial portions of the Software.
107+
108+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
109+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
110+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
111+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
112+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
113+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
114+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
115+
OTHER DEALINGS IN THE SOFTWARE.

composer-require-checker.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"symbol-whitelist" : [
3+
"null", "true", "false",
4+
"static", "self", "parent",
5+
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object",
6+
"WyriHaximus\\Constants\\ComposerAutoloader\\LOCATION", "WyriHaximus\\Constants\\Boolean\\FALSE_",
7+
"WyriHaximus\\Constants\\Boolean\\TRUE_", "WyriHaximus\\Constants\\Numeric\\ZERO"
8+
],
9+
"php-core-extensions" : [
10+
"Core",
11+
"date",
12+
"pcre",
13+
"Phar",
14+
"Reflection",
15+
"SPL",
16+
"standard"
17+
],
18+
"scan-files" : []
19+
}

0 commit comments

Comments
 (0)