From 8d6cf3730caf939037ca7995d6b1b6316d6d5b37 Mon Sep 17 00:00:00 2001 From: chaz6chez Date: Thu, 17 Oct 2024 14:13:14 +0800 Subject: [PATCH] doc update --- ...ls-Coroutine-Handlers-SwooleCoroutine.html | 12 +- ...bunny-WebmanCoroutine-Utils-Pool-Pool.html | 262 +++++++++++++++--- .../Handlers/SwooleCoroutine.php.txt | 4 + docs/files/src/Utils/Pool/Pool.php.txt | 58 +++- docs/js/searchIndex.js | 17 +- 5 files changed, 306 insertions(+), 47 deletions(-) diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-SwooleCoroutine.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-SwooleCoroutine.html index a8154d8..3681f1e 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-SwooleCoroutine.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-Coroutine-Handlers-SwooleCoroutine.html @@ -282,9 +282,9 @@

销毁协程

@@ -332,9 +332,9 @@

获取协程id

@@ -386,9 +386,9 @@

获取协程原始返回

diff --git a/docs/classes/Workbunny-WebmanCoroutine-Utils-Pool-Pool.html b/docs/classes/Workbunny-WebmanCoroutine-Utils-Pool-Pool.html index 320c54e..fa0bb51 100644 --- a/docs/classes/Workbunny-WebmanCoroutine-Utils-Pool-Pool.html +++ b/docs/classes/Workbunny-WebmanCoroutine-Utils-Pool-Pool.html @@ -169,12 +169,19 @@

析构等待销毁
+
+ append() + +  : void +
+
追加
+
create()  : array<string|int, Pool>
-
创建
+
初始化
destroy() @@ -183,6 +190,13 @@

回收
+
+ exists() + +  : bool +
+
区域/区域对象是否存在
+
get() @@ -218,6 +232,13 @@

获取空闲池
+
+ init() + +  : void +
+
初始化占位
+
isClone() @@ -295,9 +316,9 @@

构造

@@ -370,9 +391,9 @@

析构等待销毁

@@ -391,6 +412,66 @@

+ +
+

+ append() + + +

+ + +

追加

+ + + public + static append(string $name, int $index, mixed $element) : void + +
+
+ + +
Parameters
+
+
+ $name + : string +
+
+ +
+
+ $index + : int +
+
+ +
+
+ $element + : mixed +
+
+ +
+
+ + + + + +
-

创建

+

初始化

public @@ -485,9 +566,9 @@

回收

@@ -530,6 +611,63 @@

Parameters
+
+
+

+ exists() + + +

+ + +

区域/区域对象是否存在

+ + + public + static exists(string $name, int|null $index) : bool + +
+
+ + +
Parameters
+
+
+ $name + : string +
+
+ +
+
+ $index + : int|null +
+
+ +
+
+ + + + + +
+
Return values
+ bool +
+

获取

@@ -602,9 +740,9 @@

获取元素

@@ -642,9 +780,9 @@

所在区域的索引

@@ -682,9 +820,9 @@

获取所在区域名称

@@ -722,9 +860,9 @@

获取空闲池

@@ -757,6 +895,59 @@

Return values
Pool|null +
+
+

+ init() + + +

+ + +

初始化占位

+ + + public + static init(string $name[, bool $clone = true ]) : void + +
+
+ + +
Parameters
+
+
+ $name + : string +
+
+ +
+
+ $clone + : bool + = true
+
+ +
+
+ + + + + +

是否是深拷贝

@@ -812,9 +1003,9 @@

是否强制回收

@@ -852,9 +1043,9 @@

是否闲置

@@ -892,9 +1083,9 @@

设置强制回收

@@ -938,9 +1129,9 @@

设置状态

@@ -984,9 +1175,9 @@

等待至闲置

@@ -1032,9 +1223,9 @@

等待空闲并执行

@@ -1199,13 +1390,16 @@

Parameters
  • __construct()
  • __destruct()
  • +
  • append()
  • create()
  • destroy()
  • +
  • exists()
  • get()
  • getElement()
  • getIndex()
  • getName()
  • idle()
  • +
  • init()
  • isClone()
  • isForce()
  • isIdle()
  • diff --git a/docs/files/src/Utils/Coroutine/Handlers/SwooleCoroutine.php.txt b/docs/files/src/Utils/Coroutine/Handlers/SwooleCoroutine.php.txt index d035c1b..b040de9 100644 --- a/docs/files/src/Utils/Coroutine/Handlers/SwooleCoroutine.php.txt +++ b/docs/files/src/Utils/Coroutine/Handlers/SwooleCoroutine.php.txt @@ -33,6 +33,10 @@ class SwooleCoroutine implements CoroutineInterface $this->_id = $id; break; } + // 保证协程切换 + // @codeCoverageIgnoreStart + sleep(0); + // @codeCoverageIgnoreEnd } } diff --git a/docs/files/src/Utils/Pool/Pool.php.txt b/docs/files/src/Utils/Pool/Pool.php.txt index 70b5daf..6265dc0 100644 --- a/docs/files/src/Utils/Pool/Pool.php.txt +++ b/docs/files/src/Utils/Pool/Pool.php.txt @@ -21,6 +21,11 @@ class Pool */ protected static array $pools = []; + /** + * @var bool[] + */ + protected static array $poolIsClone = []; + /** * 名称 * @@ -64,7 +69,7 @@ class Pool protected bool $_force; /** - * 创建 + * 初始化 * * @param string $name 区域 * @param int $count 区域索引 @@ -74,16 +79,57 @@ class Pool */ public static function create(string $name, int $count, mixed $element, bool $clone = true): array { - if (static::get($name, null)) { - throw new PoolException("Pools $name already exists. ", -1); - } + // 占位 + static::init($name, $clone); + // 追加 foreach (range(1, $count) as $i) { - self::$pools[$name][$i] = new Pool($name, $i, $element, $clone); + static::append($name, $i, $element); } - return self::$pools[$name]; } + /** + * 区域/区域对象是否存在 + * + * @param string $name + * @param int|null $index + * @return bool + */ + public static function exists(string $name, ?int $index): bool + { + return $index === null ? isset(self::$pools[$name]) : isset(self::$pools[$name][$index]); + } + + /** + * 初始化占位 + * + * @param string $name + * @param bool $clone + * @return void + */ + public static function init(string $name, bool $clone = true): void + { + if (static::exists($name, null)) { + throw new PoolException("Pools $name already exists. ", -1); + } + self::$pools[$name] = []; + self::$poolIsClone[$name] = $clone; + } + + /** + * 追加 + * + * @param string $name + * @param int $index + * @param mixed $element + * @return void + */ + public static function append(string $name, int $index, mixed $element): void + { + $clone = self::$poolIsClone[$name] ?? false; + self::$pools[$name][$index] = new Pool($name, $index, $element, $clone); + } + /** * 回收 * diff --git a/docs/js/searchIndex.js b/docs/js/searchIndex.js index 1c86388..de970ec 100644 --- a/docs/js/searchIndex.js +++ b/docs/js/searchIndex.js @@ -928,8 +928,23 @@ Search.appendIndex( }, { "fqsen": "\\Workbunny\\WebmanCoroutine\\Utils\\Pool\\Pool\u003A\u003Acreate\u0028\u0029", "name": "create", - "summary": "\u521B\u5EFA", + "summary": "\u521D\u59CB\u5316", "url": "classes/Workbunny-WebmanCoroutine-Utils-Pool-Pool.html#method_create" + }, { + "fqsen": "\\Workbunny\\WebmanCoroutine\\Utils\\Pool\\Pool\u003A\u003Aexists\u0028\u0029", + "name": "exists", + "summary": "\u533A\u57DF\/\u533A\u57DF\u5BF9\u8C61\u662F\u5426\u5B58\u5728", + "url": "classes/Workbunny-WebmanCoroutine-Utils-Pool-Pool.html#method_exists" + }, { + "fqsen": "\\Workbunny\\WebmanCoroutine\\Utils\\Pool\\Pool\u003A\u003Ainit\u0028\u0029", + "name": "init", + "summary": "\u521D\u59CB\u5316\u5360\u4F4D", + "url": "classes/Workbunny-WebmanCoroutine-Utils-Pool-Pool.html#method_init" + }, { + "fqsen": "\\Workbunny\\WebmanCoroutine\\Utils\\Pool\\Pool\u003A\u003Aappend\u0028\u0029", + "name": "append", + "summary": "\u8FFD\u52A0", + "url": "classes/Workbunny-WebmanCoroutine-Utils-Pool-Pool.html#method_append" }, { "fqsen": "\\Workbunny\\WebmanCoroutine\\Utils\\Pool\\Pool\u003A\u003Adestroy\u0028\u0029", "name": "destroy",