fix multiple prompt timer bug

This commit is contained in:
crazywhalecc
2023-02-12 00:19:53 +08:00
committed by Jerry
parent b61421f2b6
commit ae742c1568
4 changed files with 23 additions and 3 deletions

View File

@@ -16,6 +16,7 @@ use ZM\Context\Trait\BotActionTrait;
use ZM\Exception\OneBot12Exception;
use ZM\Exception\WaitTimeoutException;
use ZM\Plugin\OneBot12Adapter;
use ZM\Schedule\Timer;
use ZM\Utils\MessageUtil;
class BotContext implements ContextInterface
@@ -114,14 +115,14 @@ class BotContext implements ContextInterface
}
$cid = $co->getCid();
OneBot12Adapter::addContextPrompt($cid, $event);
$co->create(function () use ($cid, $timeout) {
Adaptive::sleep($timeout);
$timer_id = zm_timer_after($timeout * 1000, function () use ($cid) {
if (OneBot12Adapter::isContextPromptExists($cid)) {
Adaptive::getCoroutine()->resume($cid, '');
}
});
$result = $co->suspend();
OneBot12Adapter::removeContextPrompt($cid);
Timer::del($timer_id);
if ($result === '') {
throw new WaitTimeoutException(
$this,

View File

@@ -47,7 +47,7 @@ class Framework
public const VERSION_ID = 689;
/** @var string 版本名称 */
public const VERSION = '3.0.1';
public const VERSION = '3.0.2';
/** @var array 传入的参数 */
protected array $argv;

View File

@@ -19,6 +19,11 @@ class Timer
return Framework::getInstance()->getDriver()->getEventLoop()->addTimer($ms, $callback);
}
public static function del(int $timer_id): void
{
Framework::getInstance()->getDriver()->getEventLoop()->clearTimer($timer_id);
}
public static function registerTick(Tick $v): void
{
if ($v->class !== '' && $v->method !== '') {