diff --git a/src/ZM/Framework.php b/src/ZM/Framework.php index a6d24bf9..d765561e 100644 --- a/src/ZM/Framework.php +++ b/src/ZM/Framework.php @@ -50,7 +50,7 @@ class Framework public const VERSION_ID = 718; /** @var string 版本名称 */ - public const VERSION = '3.1.12'; + public const VERSION = '3.1.13'; /** * @var RuntimePreferences 运行时偏好(环境信息&参数) diff --git a/src/ZM/Schedule/Timer.php b/src/ZM/Schedule/Timer.php index d366ce72..92cff9c5 100644 --- a/src/ZM/Schedule/Timer.php +++ b/src/ZM/Schedule/Timer.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace ZM\Schedule; +use OneBot\Driver\Coroutine\Adaptive; use ZM\Annotation\Framework\Tick; use ZM\Framework; @@ -11,12 +12,19 @@ class Timer { public static function tick(int $ms, callable $callback, int $times = 0): int { - return Framework::getInstance()->getDriver()->getEventLoop()->addTimer($ms, $callback, $times); + return Framework::getInstance()->getDriver()->getEventLoop()->addTimer( + $ms, + fn (...$params) => Adaptive::getCoroutine() !== null ? Adaptive::getCoroutine()->create($callback, ...$params) : $callback(...$params), + $times + ); } public static function after(int $ms, callable $callback): int { - return Framework::getInstance()->getDriver()->getEventLoop()->addTimer($ms, $callback); + return Framework::getInstance()->getDriver()->getEventLoop()->addTimer( + $ms, + fn (...$params) => Adaptive::getCoroutine() !== null ? Adaptive::getCoroutine()->create($callback, ...$params) : $callback(...$params) + ); } public static function del(int $timer_id): void