Skip to content

Commit

Permalink
👷 add github CI
Browse files Browse the repository at this point in the history
  • Loading branch information
matyo91 committed Apr 24, 2021
1 parent 02efbc7 commit d7cee78
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 17 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/code-quality.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Code Quality

on:
push:
branches:
- master
pull_request:

jobs:
code-quality:
name: Code Quality
runs-on: ubuntu-latest

strategy:
matrix:
php: [ '7.2', '7.3' ]

steps:
- name: 'Init repository'
uses: actions/checkout@v2

- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: xsl, swoole
tools: composer

- name: "Install dependencies"
run: composer install

- name: 'Tests unit'
run: composer tests-unit

- name: 'Tests examples'
run: composer tests-examples

- name: 'Static analysis'
run: composer static-analysis
2 changes: 1 addition & 1 deletion src/Adapter/Amp/EventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class EventLoop implements \M6Web\Tornado\EventLoop
/**
* {@inheritdoc}
*/
public function wait(Promise $promise): mixed
public function wait(Promise $promise)
{
try {
$result = \Amp\Promise\wait(
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/ReactPhp/EventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(\React\EventLoop\LoopInterface $reactEventLoop)
/**
* {@inheritdoc}
*/
public function wait(Promise $promise): mixed
public function wait(Promise $promise)
{
$value = null;
$isRejected = false;
Expand Down
11 changes: 4 additions & 7 deletions src/Adapter/Swoole/EventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ public function __destruct()
//Event::exit();
}

private function shiftCoroutine(): mixed
private function shiftCoroutine(): void
{
if (count($this->cids) === 0) {
return null;
return;
}

$cid = array_shift($this->cids);
Expand All @@ -70,17 +70,14 @@ private function shiftCoroutine(): mixed
} else {
$this->shiftCoroutine();
}

return $cid;
}

private function pushCoroutine(): mixed
private function pushCoroutine(): void
{
$cid = Coroutine::getCid();
$this->cids[] = $cid;
Coroutine::yield();

return $cid;
}

private function createPromise(): DummyPromise
Expand Down Expand Up @@ -144,7 +141,7 @@ private function isPending(DummyPromise $promise): bool
/**
* {@inheritdoc}
*/
public function wait(Promise $promise): mixed
public function wait(Promise $promise)
{
$promise = DummyPromise::wrap($promise);

Expand Down
22 changes: 19 additions & 3 deletions src/Adapter/Swoole/Internal/DummyPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,24 @@

final class DummyPromise implements Promise, Deferred
{
private bool $isPending;
private mixed $value;
private ?Throwable $exception;
/**
* @var bool
*/
private $isPending;

/**
* @var mixed
*/
private $value;

/**
* @var Throwable|null
*/
private $exception;

/**
* @var callable[]
*/
private $callbacks;

public function __construct(?callable $callback = null)
Expand Down Expand Up @@ -43,6 +58,7 @@ public function resolve($value): void

$this->isPending = false;
$this->value = $value;

foreach ($this->callbacks as $callback) {
($callback)($this);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/Swoole/PromiseEventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct()
/**
* {@inheritdoc}
*/
public function wait(Promise $promise): mixed
public function wait(Promise $promise)
{
$value = null;
$isRejected = false;
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/Swoole/YieldEventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct()
/**
* {@inheritdoc}
*/
public function wait(Promise $promise): mixed
public function wait(Promise $promise)
{
$value = null;
$this->async((static function () use ($promise, &$value): \Generator {
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/Tornado/EventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct()
/**
* {@inheritdoc}
*/
public function wait(Promise $promise): mixed
public function wait(Promise $promise)
{
$promiseIsPending = true;
$finalAction = function () {throw new \Error('Impossible to resolve the promise, no more task to execute..'); };
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/Tornado/SynchronousEventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SynchronousEventLoop implements \M6Web\Tornado\EventLoop
/**
* {@inheritdoc}
*/
public function wait(Promise $promise): mixed
public function wait(Promise $promise)
{
// If there are some uncaught exceptions, throw the first one.
if ($throwable = reset($this->asyncThrowables)) {
Expand Down
4 changes: 3 additions & 1 deletion src/EventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ interface EventLoop
/**
* Waits the resolution of a promise, and returns its value.
* You should use this function once for your global result.
*
* @return mixed
*/
public function wait(Promise $promise): mixed;
public function wait(Promise $promise);

/**
* Registers a generator in the event loop to execute it asynchronously.
Expand Down

0 comments on commit d7cee78

Please sign in to comment.