add cs fixer and PHPStan and activate it (build 436)

This commit is contained in:
crazywhalecc
2022-03-15 18:05:33 +08:00
parent d01bd69aa5
commit 1706afbcd0
163 changed files with 4572 additions and 3588 deletions

View File

@@ -1,9 +1,9 @@
<?php
declare(strict_types=1);
namespace ZM\Utils;
use Swoole\Coroutine;
class CoroutinePool
@@ -16,8 +16,11 @@ class CoroutinePool
private static $yields = [];
public static function go(callable $func, $name = "default") {
if (!isset(self::$cids[$name])) self::$cids[$name] = [];
public static function go(callable $func, $name = 'default')
{
if (!isset(self::$cids[$name])) {
self::$cids[$name] = [];
}
if (count(self::$cids[$name]) >= (self::$sizes[$name] ?? self::$default_size)) {
self::$yields[] = Coroutine::getCid();
Coroutine::suspend();
@@ -30,19 +33,23 @@ class CoroutinePool
});
}
public static function defaultSize(int $size) {
public static function defaultSize(int $size)
{
self::$default_size = $size;
}
public static function setSize($name, int $size) {
public static function setSize($name, int $size)
{
self::$sizes[$name] = $size;
}
public static function getRunningCoroutineCount($name = "default") {
public static function getRunningCoroutineCount($name = 'default')
{
return count(self::$cids[$name]);
}
private static function checkCids($name) {
private static function checkCids($name)
{
if (in_array(Coroutine::getCid(), self::$cids[$name])) {
$a = array_search(Coroutine::getCid(), self::$cids[$name]);
array_splice(self::$cids[$name], $a, 1);