Skip to content

Commit be9a5da

Browse files
committed
fix: fix setTimeout can't be cancelled #219
1 parent 282e063 commit be9a5da

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Fixed setTimeout can't be cancelled #219
13+
1014
## [0.9.3] - 2025-01-30
1115

1216
### Fixed

src/legacy/engine/TimeTaskSystem.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,14 @@ int NewTimeout(Local<Function> func, std::vector<Local<Value>> paras, int timeou
5151
ll::coro::keepThis([timeout, tid, data]() -> ll::coro::CoroTask<> {
5252
co_await std::chrono::milliseconds(timeout);
5353
try {
54-
if ((ll::getGamingStatus() == ll::GamingStatus::Stopping) || !EngineManager::isValid(data.engine))
54+
if (!CheckTimeTask(tid)) {
5555
co_return;
56+
}
57+
58+
if ((ll::getGamingStatus() == ll::GamingStatus::Stopping) || !EngineManager::isValid(data.engine)) {
59+
ClearTimeTask(tid);
60+
co_return;
61+
}
5662

5763
EngineScope scope(data.engine);
5864
if (!data.func.isEmpty()) {
@@ -83,8 +89,14 @@ int NewTimeout(Local<String> func, int timeout) {
8389
ll::coro::keepThis([timeout, tid, data]() -> ll::coro::CoroTask<> {
8490
co_await std::chrono::milliseconds(timeout);
8591
try {
86-
if ((ll::getGamingStatus() == ll::GamingStatus::Stopping) || !EngineManager::isValid(data.engine))
92+
if (!CheckTimeTask(tid)) {
8793
co_return;
94+
}
95+
96+
if ((ll::getGamingStatus() == ll::GamingStatus::Stopping) || !EngineManager::isValid(data.engine)) {
97+
ClearTimeTask(tid);
98+
co_return;
99+
}
88100

89101
EngineScope scope(data.engine);
90102
if (!data.code.isEmpty()) {

xmake.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ add_rules("mode.debug", "mode.release")
33
add_repositories("liteldev-repo https://github.com/LiteLDev/xmake-repo.git")
44

55
if is_config("target_type", "server") then
6-
add_requires("levilamina 1.0.0", {configs = {target_type = "server"}})
6+
add_requires("levilamina 1.0.1", {configs = {target_type = "server"}})
77
else
8-
add_requires("levilamina 1.0.0", {configs = {target_type = "client"}})
8+
add_requires("levilamina 1.0.1", {configs = {target_type = "client"}})
99
end
1010

1111
add_requires("levibuildscript")

0 commit comments

Comments
 (0)