From 8105892b6e5a560eed12396aec5aaa9f3db4e681 Mon Sep 17 00:00:00 2001 From: sunxyw Date: Mon, 21 Mar 2022 23:28:57 +0800 Subject: [PATCH] fix review --- src/ZM/Event/EventManager.php | 4 ++-- src/ZM/global_functions.php | 21 ++------------------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/src/ZM/Event/EventManager.php b/src/ZM/Event/EventManager.php index a93f0ae5..246983b6 100644 --- a/src/ZM/Event/EventManager.php +++ b/src/ZM/Event/EventManager.php @@ -83,9 +83,9 @@ class EventManager } $conf = ZMConfig::get('global', 'worker_cache') ?? ['worker' => 0]; if (server()->worker_id == $conf['worker']) { - run_repeating(static function () { + zm_timer_tick(ZMConfig::get('global', 'light_cache')['auto_save_interval'] * 1000, static function () { LightCache::savePersistence(); - }, ZMConfig::get('global', 'light_cache')['auto_save_interval'] * 1000); + }); } } } diff --git a/src/ZM/global_functions.php b/src/ZM/global_functions.php index 174c83ac..2e6a455f 100644 --- a/src/ZM/global_functions.php +++ b/src/ZM/global_functions.php @@ -345,7 +345,7 @@ function zm_resume(int $cid) * * @param int $delay 延迟时间,单位毫秒ms */ -function run_later(callable $runnable, int $delay) +function zm_timer_after(int $delay, callable $runnable) { Swoole\Timer::after($delay, static function () use ($runnable) { call_with_catch($runnable); @@ -358,7 +358,7 @@ function run_later(callable $runnable, int $delay) * @param int $interval 间隔时间,单位毫秒ms * @return false|int 定时器ID,失败返回false */ -function run_repeating(callable $runnable, int $interval) +function zm_timer_tick(int $interval, callable $runnable) { if (zm_cid() === -1) { return go(static function () use ($interval, $runnable) { @@ -719,15 +719,6 @@ function onebot_target_id_name(string $message_type): string return get_onebot_target_id_name($message_type); } -/** - * @param mixed $ms - * @deprecated 已废弃,请使用 {@link run_repeating()} - */ -function zm_timer_tick($ms, callable $callable) -{ - return run_repeating($callable, $ms); -} - /** * @deprecated 已废弃,请直接使用 {@link call_with_catch()} */ @@ -744,11 +735,3 @@ function zm_data_hash($v): string { return hash_message($v); } - -/** - * @deprecated 已废弃,请使用 {@link run_later()} - */ -function zm_timer_after(int $ms, callable $callable) -{ - run_later($callable, $ms); -}