react-parallel/infinite-pool

♾️ 用于连接 ext-parallel 和 ReactPHP 的无限池

2.1.2 2020-11-21 12:37 UTC

README

Continuous Integration Latest Stable Version Total Downloads Code Coverage Type Coverage License

ext-parallel-infinite-pool 的 ReactPHP 绑定

安装

要通过 Composer 安装,请使用以下命令,它将自动检测最新版本并将其与 ~ 绑定。

composer require react-parallel/infinite-pool 

用法

以下示例将启动一个具有 1 秒 TTL 清理策略的线程。这意味着线程将在 1 秒内等待进行操作,然后关闭。然后在该线程中运行一个闭包,该闭包将在返回消息之前等待 1 秒。接收到该消息后,主线程将在关闭池之前回显该消息;

use React\EventLoop\Factory;
use ReactParallel\EventLoop\EventLoopBridge;
use ReactParallel\Pool\Infinite\Infinite;

$loop = Factory::create();
$infinite = new Infinite($loop, new EventLoopBridge($loop), 1);
$infinite->run(function () {
    sleep(1);

    return 'Hoi!';
})->then(function (string $message) use ($infinite) {
    echo $message, PHP_EOL;
    $infinite->close();
});
$loop->run();

指标

此包通过 wyrihaximus/metrics 支持指标

use React\EventLoop\Factory;
use ReactParallel\EventLoop\EventLoopBridge;
use ReactParallel\EventLoop\Metrics as EventLoopMetrics;
use ReactParallel\Pool\Infinite\Infinite;
use ReactParallel\Pool\Infinite\Metrics;
use WyriHaximus\Metrics\Configuration;
use WyriHaximus\Metrics\InMemory\Registry;

$loop = Factory::create();
$registry = new Registry(Configuration::create());
$eventLoopBridge = (new EventLoopBridge($loop))->withMetrics(EventLoopMetrics::create($registry));
$finite = (new Infinite($loop, $eventLoopBridge, 1.3))->withMetrics(Metrics::create($registry));

许可证

版权所有 2020 Cees-Jan Kiewiet

特此授予任何获得本软件及其相关文档副本(“软件”)的人免费使用软件的权利,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件副本的权利,并允许软件提供方从事此类行为,前提是遵守以下条件

上述版权声明和本许可声明应包含在软件的副本或主要部分中。

软件按“现状”提供,不提供任何明示或暗示的保证,包括但不限于对适销性、针对特定目的的适用性和非侵权的保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论此类索赔、损害或其他责任是基于合同、侵权或其他方式,以及与软件或软件的使用或其他交易有关。