正在显示
1 个修改的文件
包含
59 行增加
和
0 行删除
lib/SwGo.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace Lib; | ||
4 | + | ||
5 | + | ||
6 | +/** | ||
7 | + * 这个是协程封装 | ||
8 | + * @author:dc | ||
9 | + * @time 2025/3/17 11:22 | ||
10 | + * Class SwGo | ||
11 | + * @package Lib | ||
12 | + */ | ||
13 | +class SwGo { | ||
14 | + | ||
15 | + /** | ||
16 | + * 运行状态 | ||
17 | + * @var array | ||
18 | + */ | ||
19 | + public static $runStatus = []; | ||
20 | + | ||
21 | + /** | ||
22 | + * 已经运行的go数量 | ||
23 | + * @var int | ||
24 | + */ | ||
25 | + public static $runNumber = 0; | ||
26 | + | ||
27 | + | ||
28 | + /** | ||
29 | + * | ||
30 | + * @param \Closure $run | ||
31 | + * @param \Closure $end | ||
32 | + * @author:dc | ||
33 | + * @time 2025/3/17 11:35 | ||
34 | + */ | ||
35 | + public static function start(\Closure $run,...$param): bool | ||
36 | + { | ||
37 | + | ||
38 | + go(function (\Closure $run,...$param){ | ||
39 | + self::$runNumber++; | ||
40 | + | ||
41 | + $run(...$param); | ||
42 | + | ||
43 | + // 写入日志 | ||
44 | + \Lib\Log::getInstance()->write(); | ||
45 | + // 释放 mysql | ||
46 | + db()->close(); | ||
47 | + // 释放redis | ||
48 | + redis()->close(); | ||
49 | + | ||
50 | + self::$runNumber--; | ||
51 | + | ||
52 | + },$run,...$param); | ||
53 | + | ||
54 | + return true; | ||
55 | + } | ||
56 | + | ||
57 | + | ||
58 | + | ||
59 | +} |
-
请 注册 或 登录 后发表评论