darkwood / flow
Flow
v1.2.2
2024-08-30 17:02 UTC
Requires
- php: >=8.3
- symfony/event-dispatcher: ^7.0
- symfony/messenger: ^7.0
Requires (Dev)
- amphp/amp: ^3.0
- openswoole/ide-helper: ^22.1.5
- react/async: ^4.3
- spatie/async: ^1.6
- symfony/doctrine-messenger: ^7.0
- symfony/orm-pack: ^2.4
Suggests
- ext-openswoole: Provide asynchronous with OpenSwoole
- amphp/amp: Provide asynchronous with AMP
- react/async: Provide asynchronous with ReactPHP
- spatie/async: Provide asynchronous with Spatie
- symfony/messenger: Provide Symfony Messenger support
This package is auto-updated.
Last update: 2024-09-17 23:33:37 UTC
README
为什么?
Flow 概念旨在解决
- 采用异步作为原生实现
- 使用函数式编程构建你的代码
- 可视地组装你的代码
安装
PHP 8.3 是使用 Flow 的最低版本。推荐通过 Composer 安装并执行
composer require darkwood/flow
用法
<?php use Flow\Flow\Flow; use Flow\Ip; class D1 { public function __construct(public int $n1) {} } class D2 { public function __construct(public int $n2) {} } class D3 { public function __construct(public int $n3) {} } class D4 { public function __construct(public int $n4) {} } $flow = Flow::do(static function() { yield fn (D1 $data1) => new D2($data1->n1 += 1); yield fn (D2 $data2) => new D3($data2->n2 * 2); yield function(D3 $data3) { printf("my number %d\n", $ip->data->n3)); // display 'my number 10' return new D4($data3->n3); }; }); $ip = new Ip(new D1(4)); $flow($ip); $flow->await();
示例
一个可工作的脚本位于捆绑的 examples
目录中
- 运行 Flow :
php examples/flow.php
- 运行 Y-Combinator Flow :
php examples/yflow.php
- 启动服务器 :
php examples/server.php
启动客户端 :php examples/client.php
文档
https://darkwood-com.github.io/flow
许可证
Flow 在 MIT 许可证下发布。