Skip to content

Commit 30e15fa

Browse files
author
AstroAir
committed
refactor: reorganize examples and fix compiler warnings
- Reorganize example files into logical subdirectories - Fix unused parameter warnings across multiple modules - Remove obsolete example and test files - Update CMakeLists.txt to reflect new structure - Fix MSVC compatibility issues in various modules - Fix markdown linting issues in README files
1 parent 4ba3eef commit 30e15fa

149 files changed

Lines changed: 2954 additions & 27544 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude/settings.local.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@
9797
"Bash(then cp -v build/atom/error/libatom-error.dll build/atom/log/libatom-log.dll build/atom/log/libloguru.dll build/atom/components/libatom-component.dll \"$dir\")",
9898
"Bash(./test_abi.exe:*)",
9999
"Bash(pkill:*)",
100-
"Bash(test:*)"
100+
"Bash(test:*)",
101+
"Bash(dir /s /b atomsystem*.hpp atomsystem*.h atomsystem*.cpp 2)",
102+
"Bash(nul)",
103+
"Bash(powershell:*)"
101104
],
102105
"deny": [],
103106
"ask": []

atom/async/core/async.hpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,20 @@ void AsyncWorker<void>::startAsync(Func&& func, Args&&... args) {
12461246
}
12471247
}
12481248

1249+
inline void AsyncWorker<void>::getResult(std::chrono::milliseconds timeout) {
1250+
if (!task_.valid()) {
1251+
throw std::invalid_argument("Task is not valid");
1252+
}
1253+
1254+
if (timeout.count() > 0) {
1255+
if (task_.wait_for(timeout) != std::future_status::ready) {
1256+
THROW_TIMEOUT_EXCEPTION("Task result retrieval timed out");
1257+
}
1258+
}
1259+
1260+
task_.get();
1261+
}
1262+
12491263
inline void AsyncWorker<void>::cancel() noexcept {
12501264
try {
12511265
if (task_.valid()) {
@@ -1292,6 +1306,41 @@ inline auto AsyncWorker<void>::isActive() const noexcept -> bool {
12921306
return state_.load(std::memory_order_acquire) == State::RUNNING;
12931307
}
12941308

1309+
inline auto AsyncWorker<void>::validate(
1310+
std::function<bool()> validator) noexcept -> bool {
1311+
try {
1312+
if (!validator) {
1313+
return false;
1314+
}
1315+
1316+
if (!isDone()) {
1317+
return false;
1318+
}
1319+
1320+
if (task_.valid()) {
1321+
task_.get();
1322+
}
1323+
1324+
return validator();
1325+
} catch (...) {
1326+
return false;
1327+
}
1328+
}
1329+
1330+
inline void AsyncWorker<void>::setCallback(std::function<void()> callback) {
1331+
if (!callback) {
1332+
throw std::invalid_argument("Callback function cannot be null");
1333+
}
1334+
callback_ = std::move(callback);
1335+
}
1336+
1337+
inline void AsyncWorker<void>::setTimeout(std::chrono::seconds timeout) {
1338+
if (timeout < std::chrono::seconds(0)) {
1339+
throw std::invalid_argument("Timeout cannot be negative");
1340+
}
1341+
timeout_ = timeout;
1342+
}
1343+
12951344
// Implementation of AsyncWorker methods
12961345
template <typename ResultType>
12971346
template <typename Func, typename... Args>

atom/async/utils/timer.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,16 @@ void TimerTask::run() noexcept(false) {
6868
THROW_RUNTIME_ERROR("Failed to run timer task: Unknown error");
6969
}
7070

71+
const auto nextExecution =
72+
std::chrono::steady_clock::now() + std::chrono::milliseconds(m_delay);
73+
7174
if (m_repeatCount > 0) {
7275
--m_repeatCount;
7376
if (m_repeatCount > 0) {
74-
m_nextExecutionTime = std::chrono::steady_clock::now() +
75-
std::chrono::milliseconds(m_delay);
77+
m_nextExecutionTime = nextExecution;
7678
}
79+
} else if (m_repeatCount == -1) {
80+
m_nextExecutionTime = nextExecution;
7781
}
7882
}
7983

@@ -247,7 +251,8 @@ void Timer::run() noexcept {
247251
try {
248252
m_currentTask.run();
249253

250-
if (m_currentTask.m_repeatCount > 0) {
254+
if (m_currentTask.m_repeatCount > 0 ||
255+
m_currentTask.m_repeatCount == -1) {
251256
m_taskContainer.push(m_currentTask);
252257
}
253258

@@ -338,7 +343,7 @@ void Timer::run() noexcept {
338343
try {
339344
task.run();
340345

341-
if (task.m_repeatCount > 0) {
346+
if (task.m_repeatCount > 0 || task.m_repeatCount == -1) {
342347
std::scoped_lock innerLock(m_mutex);
343348
m_taskQueue.emplace(task.m_func, task.m_delay,
344349
task.m_repeatCount,

0 commit comments

Comments
 (0)