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

Await #50

Merged
merged 2 commits into from
Apr 14, 2024
Merged
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
20 changes: 10 additions & 10 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# php: [ '8.2' ]
# php: [ '8.3' ]
# steps:
# - name: Init repository
# uses: actions/checkout@v3
Expand All @@ -37,7 +37,7 @@ jobs:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# php: [ '8.2' ]
# php: [ '8.3' ]
# steps:
# - name: Init repository
# uses: actions/checkout@v3
Expand All @@ -62,7 +62,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '8.2' ]
php: [ '8.3' ]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -88,7 +88,7 @@ jobs:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# php: [ '8.2' ]
# php: [ '8.3' ]
# steps:
# - name: Init repository
# uses: actions/checkout@v3
Expand All @@ -113,7 +113,7 @@ jobs:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# php: [ '8.2' ]
# php: [ '8.3' ]
# steps:
# - name: Init repository
# uses: actions/checkout@v3
Expand All @@ -138,7 +138,7 @@ jobs:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# php: [ '8.2' ]
# php: [ '8.3' ]
# steps:
# - name: Init repository
# uses: actions/checkout@v3
Expand All @@ -163,7 +163,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '8.2' ]
php: [ '8.3' ]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -189,7 +189,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '8.2' ]
php: [ '8.3' ]
steps:
- name: Init repository
uses: actions/checkout@v3
Expand All @@ -215,7 +215,7 @@ jobs:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# php: [ '8.2' ]
# php: [ '8.3' ]
# steps:
# - name: Init repository
# uses: actions/checkout@v3
Expand All @@ -233,4 +233,4 @@ jobs:
# composer install -d tools/psalm
#
# - name: Run PHP Mess Detector
# run: (cd tools && psalm/vendor/bin/psalm --no-cache --config psalm/psalm.xml)
# run: (cd tools && psalm/vendor/bin/psalm --no-cache --config psalm/psalm.xml)
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v1.2.0

- Add event system for processing IpStrategy
- Remove `start` and `stop` in favor of `await` for Flow\DriverInterface

## v1.1.5

- Add Flow\FlowInterface::do notation from https://github.com/fp4php/functional
Expand All @@ -8,12 +13,12 @@
- array : constructor arguments for Flow instanciation
- array (view as shape) : configuration for Flow instanciation
- FlowInterface : the FlowInterface instance itself
- array : map of all possible above choices
- Update to Symfony 7.0

## v1.1.4

- Add generic templating
- Add Flow\Driver\RevoltDriver
- Add Flow\Driver\SpatieDriver
- Add more quality tools from https://github.com/IngeniozIT/php-skeleton

Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Flow concept aims to solve

## Installation

PHP 8.2 is the minimal version to use Flow
PHP 8.2 is the minimal version to use Flow
The recommended way to install it through [Composer](http://getcomposer.org) and execute

```bash
Expand All @@ -37,21 +37,25 @@ class D2 {
public function __construct(public int $n2) {}
}

class D3 {
public function __construct(public int $n3) {}
}

$flow = Flow::do(static function() {
yield fn (D1 $data1) => new D2($data1->n1 += 1);
yield fn (D2 $data2) => $data2->n2 * 2;
yield fn (D2 $data2) => new D3($data2->n2 * 2);
});

$ip = new Ip(new D1(4));
$flow($ip, fn ($ip) => printf("my number %d\n", $ip->data->n2)); // display 'my number 10'
$flow($ip, fn ($ip) => printf("my number %d\n", $ip->data->n3)); // display 'my number 10'
```

## Examples

A working script is available in the bundled `examples` directory

- Run Flow : `php examples/flow.php`
- Start Server : `php examples/server.php`
- Start Server : `php examples/server.php`
Start Client(s) : `php examples/client.php`

## Documentation
Expand Down
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,23 @@
"php"
],
"require": {
"php": ">=8.2"
"php": ">=8.3",
"symfony/event-dispatcher": "^7.0"
},
"require-dev": {
"amphp/amp": "^3.0",
"openswoole/ide-helper": "^22.0.1",
"openswoole/ide-helper": "^22.1.5",
"react/async": "^4.2",
"spatie/async": "^1.6",
"symfony/doctrine-messenger": "^7.0",
"symfony/messenger": "^7.0",
"symfony/orm-pack": "^2.4",
"revolt/event-loop": "^1.0.6",
"spatie/async": "^1.6"
"symfony/orm-pack": "^2.4"
},
"suggest": {
"amphp/amp": "Provide asynchronous with AMP",
"ext-openswoole": "Provide asynchronous with OpenSwoole",
"react/async": "Provide asynchronous with ReactPHP",
"symfony/messenger": "Provide Symfony Messenger support",
"revolt/event-loop": "Provide asynchronous with Revolt",
"spatie/async": "Provide asynchronous with Spatie"
},
"autoload": {
Expand Down
24 changes: 7 additions & 17 deletions docs/src/content/en/docs/getting-started/driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ Flow embark multiple drivers.

## Coroutine

Drivers are useful to essentially provide asynchronous programming by using [coroutines](https://en.wikipedia.org/wiki/Coroutine).
Drivers are useful to essentially provide asynchronous programming by using [coroutines](https://en.wikipedia.org/wiki/Coroutine).
Thus, this can be implemented in severals ways in most popular programming languages.

Coroutine are very similar to [threads](https://en.wikipedia.org/wiki/Thread_(computing)) and provide concurrency but not parallelism.
Advantage of using coroutine :
- this can be a preferred usage to thread for [hard-realtime](https://en.wikipedia.org/wiki/Real-time_computing#Hard) context.
- there is no need for synchronisation primitives such as mutexes, semaphore.
- it reduces the usage of system lock for sharing resources.
Coroutine are very similar to [threads](https://en.wikipedia.org/wiki/Thread_(computing)) and provide concurrency but not parallelism.
Advantage of using coroutine :
- this can be a preferred usage to thread for [hard-realtime](https://en.wikipedia.org/wiki/Real-time_computing#Hard) context.
- there is no need for synchronisation primitives such as mutexes, semaphore.
- it reduces the usage of system lock for sharing resources.

## Amp Driver

Expand All @@ -52,16 +52,6 @@ composer require react/async

More documentation can be found [https://reactphp.org](https://reactphp.org)

## Revolt Driver

To use Revolt Driver, you have to require the library with composer

```bash
composer require revolt/event-loop
```

More documentation can be found [https://revolt.run](https://revolt.run)

## Spatie Driver

To use Spatie Driver, you have to require the library with composer
Expand All @@ -84,4 +74,4 @@ More documentation can be found [https://openswoole.com](https://openswoole.com)

## Make your custom driver

You can make your custom driver by implementing `Flow\DriverInterface`
You can make your custom driver by implementing `Flow\DriverInterface`
12 changes: 0 additions & 12 deletions examples/Data.php

This file was deleted.

10 changes: 10 additions & 0 deletions examples/Data/DataA.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Flow\Examples\Data;

readonly class DataA
{
public function __construct(public int $id, public int $a, public int $b, public int $c) {}
}
10 changes: 10 additions & 0 deletions examples/Data/DataB.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Flow\Examples\Data;

readonly class DataB
{
public function __construct(public int $id, public int $d, public int $e) {}
}
10 changes: 10 additions & 0 deletions examples/Data/DataC.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Flow\Examples\Data;

readonly class DataC
{
public function __construct(public int $id, public int $f) {}
}
10 changes: 10 additions & 0 deletions examples/Data/DataD.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Flow\Examples\Data;

readonly class DataD
{
public function __construct(public int $id) {}
}
2 changes: 1 addition & 1 deletion examples/Transport/DoctrineIpTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DoctrineIpTransport implements TransportInterface
public function __construct(
private DbalConnection $connection,
private ?string $id = 'supervisor',
SerializerInterface $serializer = null
?SerializerInterface $serializer = null
) {
$this->serializer = $serializer ?? new PhpSerializer();
$this->senders = [];
Expand Down
4 changes: 1 addition & 3 deletions examples/Transport/Receiver/CollectionReceiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class CollectionReceiver implements ReceiverInterface
/**
* @param iterable<ReceiverInterface> $receivers
*/
public function __construct(private iterable $receivers)
{
}
public function __construct(private iterable $receivers) {}

public function get(): iterable
{
Expand Down
4 changes: 1 addition & 3 deletions examples/Transport/Sender/CollectionSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ class CollectionSender implements SenderInterface
/**
* @param iterable<SenderInterface> $senders
*/
public function __construct(private iterable $senders)
{
}
public function __construct(private iterable $senders) {}

public function send(Envelope $envelope): Envelope
{
Expand Down
5 changes: 2 additions & 3 deletions examples/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ class client
public function __construct(
private SenderInterface $sender,
private ReceiverInterface $receiver
) {
}
) {}

/**
* @param ?int $delay The delay in milliseconds
*/
public function call(object $data, int $delay = null): void
public function call(object $data, ?int $delay = null): void
{
$ip = Envelope::wrap($data, $delay ? [new DelayStamp($delay)] : []);
$this->sender->send($ip);
Expand Down
Loading
Loading