fix tick coroutine bug, update to 3.1.13

This commit is contained in:
crazywhalecc
2023-05-26 20:30:15 +08:00
committed by Jerry Ma
parent e2005af5dd
commit 92fabb0bfc
2 changed files with 11 additions and 3 deletions

View File

@@ -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 运行时偏好(环境信息&参数)

View File

@@ -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