refactor(DoTask): formatting and naming
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-01-01 07:38:06 +01:00
parent 55cb3b6ec7
commit 3d125af2ed
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
2 changed files with 6 additions and 5 deletions

View File

@ -9,17 +9,18 @@ namespace fortuna {
auto DoTask::die_pls() -> void { auto DoTask::die_pls() -> void {
do_sleep.unlock(); do_sleep.unlock();
threadie.join(); th.join();
} }
auto DoTask::thread_pls(const std::chrono::seconds& interval, auto DoTask::thread_pls(const std::chrono::seconds& interval,
std::function<void()> callback) -> void { std::function<void()> callback) -> void {
if (threadie.joinable()) {
if (th.joinable()) {
die_pls(); die_pls();
} }
do_sleep.lock(); do_sleep.lock();
threadie = std::thread([this, interval, callback = std::move(callback)] { th = std::thread([this, interval, callback = std::move(callback)] {
while (!do_sleep.try_lock_for(interval)) { while (!do_sleep.try_lock_for(interval)) {
callback(); callback();
} }
@ -27,7 +28,7 @@ auto DoTask::thread_pls(const std::chrono::seconds& interval,
} }
DoTask::~DoTask() noexcept { DoTask::~DoTask() noexcept {
if (threadie.joinable()) { if (th.joinable()) {
die_pls(); die_pls();
} }
} }

View File

@ -11,7 +11,7 @@ namespace fortuna {
class DoTask { class DoTask {
private: private:
std::timed_mutex do_sleep; std::timed_mutex do_sleep;
std::thread threadie; std::thread th;
public: public:
~DoTask() noexcept; ~DoTask() noexcept;