- Add refresh scheduler and network refresh service boundaries for typed refresh results, ordered RPC collectors, applicators, and price parsing. - Add daemon lifecycle and wallet security workflow helpers while preserving App-owned command RPC, decrypt, cancellation, and UI handoff behavior. - Split balance, console, mining, amount formatting, and async task logic into focused modules with expanded Phase 4 test coverage. - Fix market price loading by triggering price refresh immediately, avoiding queue-pressure drops, tracking loading/error state, and adding translations. - Polish send, explorer, peers, settings, theme/schema, and related tab UI. - Replace checked-in generated language headers with build-generated resources. - Document the cleanup audit, UI static-state guidance, and architecture updates.
59 lines
1.3 KiB
C++
59 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <atomic>
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <vector>
|
|
|
|
namespace dragonx {
|
|
namespace util {
|
|
|
|
class AsyncTaskManager {
|
|
public:
|
|
class Token {
|
|
public:
|
|
Token() = default;
|
|
explicit Token(std::shared_ptr<std::atomic<bool>> cancelled)
|
|
: cancelled_(std::move(cancelled)) {}
|
|
|
|
bool cancelled() const {
|
|
return cancelled_ && cancelled_->load(std::memory_order_relaxed);
|
|
}
|
|
|
|
private:
|
|
std::shared_ptr<std::atomic<bool>> cancelled_;
|
|
};
|
|
|
|
using Task = std::function<void(const Token&)>;
|
|
|
|
AsyncTaskManager() = default;
|
|
~AsyncTaskManager();
|
|
|
|
AsyncTaskManager(const AsyncTaskManager&) = delete;
|
|
AsyncTaskManager& operator=(const AsyncTaskManager&) = delete;
|
|
|
|
void submit(std::string name, Task task);
|
|
void cancelAll();
|
|
void join(const std::string& name);
|
|
void joinAll();
|
|
void reapCompleted();
|
|
bool isRunning(const std::string& name) const;
|
|
|
|
private:
|
|
struct TaskEntry {
|
|
std::string name;
|
|
std::shared_ptr<std::atomic<bool>> cancelled;
|
|
std::shared_ptr<std::atomic<bool>> done;
|
|
std::thread worker;
|
|
};
|
|
|
|
mutable std::mutex mutex_;
|
|
std::vector<TaskEntry> tasks_;
|
|
};
|
|
|
|
} // namespace util
|
|
} // namespace dragonx
|