mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-21 15:45:36 +08:00
update to 2.3.1 version (build 388)
cleanup code and fix a bug
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php /** @noinspection PhpUnused */
|
||||
|
||||
|
||||
namespace ZM\Event;
|
||||
@@ -9,7 +9,6 @@ use Error;
|
||||
use Exception;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Exception\InterruptException;
|
||||
use ZM\Exception\ZMException;
|
||||
use ZM\Store\LightCacheInside;
|
||||
use ZM\Store\Lock\SpinLock;
|
||||
use ZM\Store\ZMAtomic;
|
||||
@@ -32,7 +31,7 @@ class EventDispatcher
|
||||
/** @var bool */
|
||||
private $log = false;
|
||||
/** @var int */
|
||||
private $eid = 0;
|
||||
private $eid;
|
||||
/** @var int */
|
||||
public $status = self::STATUS_NORMAL;
|
||||
/** @var mixed */
|
||||
@@ -64,22 +63,18 @@ class EventDispatcher
|
||||
|
||||
public function __construct(string $class = '') {
|
||||
$this->class = $class;
|
||||
try {
|
||||
$this->eid = ZMAtomic::get("_event_id")->add(1);
|
||||
$list = LightCacheInside::get("wait_api", "event_trace");
|
||||
} catch (ZMException $e) {
|
||||
$list = [];
|
||||
}
|
||||
$this->eid = ZMAtomic::get("_event_id")->add(1);
|
||||
$list = LightCacheInside::get("wait_api", "event_trace");
|
||||
if (isset($list[$class])) $this->log = true;
|
||||
if ($this->log) Console::verbose("[事件分发{$this->eid}] 开始分发事件: " . $class);
|
||||
}
|
||||
|
||||
public function setRuleFunction(callable $rule = null) {
|
||||
public function setRuleFunction(callable $rule = null): EventDispatcher {
|
||||
$this->rule = $rule;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setReturnFunction(callable $return_func) {
|
||||
public function setReturnFunction(callable $return_func): EventDispatcher {
|
||||
$this->return_func = $return_func;
|
||||
return $this;
|
||||
}
|
||||
@@ -117,6 +112,7 @@ class EventDispatcher
|
||||
* @return bool
|
||||
* @throws InterruptException
|
||||
* @throws AnnotationException
|
||||
* @noinspection PhpMissingReturnTypeInspection
|
||||
*/
|
||||
public function dispatchEvent($v, $rule_func = null, ...$params) {
|
||||
$q_c = $v->class;
|
||||
|
||||
@@ -9,7 +9,6 @@ use Exception;
|
||||
use Swoole\Timer;
|
||||
use ZM\Annotation\AnnotationBase;
|
||||
use ZM\Annotation\AnnotationParser;
|
||||
use ZM\Annotation\Swoole\OnSave;
|
||||
use ZM\Annotation\Swoole\OnTick;
|
||||
use ZM\Config\ZMConfig;
|
||||
use ZM\Console\Console;
|
||||
@@ -37,6 +36,7 @@ class EventManager
|
||||
|
||||
/**
|
||||
* 注册所有计时器给每个进程
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function registerTimerTick() {
|
||||
$dispatcher = new EventDispatcher(OnTick::class);
|
||||
|
||||
@@ -127,6 +127,7 @@ class ServerEventHandler
|
||||
* @SwooleHandler("WorkerStop")
|
||||
* @param $server
|
||||
* @param $worker_id
|
||||
* @throws Exception
|
||||
*/
|
||||
public function onWorkerStop(Server $server, $worker_id) {
|
||||
if ($worker_id == (ZMConfig::get("worker_cache")["worker"] ?? 0)) {
|
||||
@@ -598,7 +599,6 @@ class ServerEventHandler
|
||||
* @param Server|null $server
|
||||
* @param Server\Task $task
|
||||
* @noinspection PhpUnusedParameterInspection
|
||||
* @return null
|
||||
*/
|
||||
public function onTask(?Server $server, Server\Task $task) {
|
||||
if (isset($task->data["task"])) {
|
||||
|
||||
Reference in New Issue
Block a user