From e275fa01ed3f87b09b14786a727109d6339d580d Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Sun, 2 Mar 2025 17:44:44 +0000 Subject: [PATCH] Add start() method to Periodic (and construct stopped) --- client/src/connection.vala | 1 + client/src/periodic.vala | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/client/src/connection.vala b/client/src/connection.vala index 211340f..f523386 100644 --- a/client/src/connection.vala +++ b/client/src/connection.vala @@ -112,6 +112,7 @@ namespace StudySystemClient { public Worker(SessionManager session_manager) { base(TASK_PERIOD_MS); this.session_manager = session_manager; + start(); } protected override void task() { diff --git a/client/src/periodic.vala b/client/src/periodic.vala index bab1281..84eb2f2 100644 --- a/client/src/periodic.vala +++ b/client/src/periodic.vala @@ -6,17 +6,25 @@ namespace StudySystemClient { protected Periodic(uint period_ms) { this.period_ms = period_ms; - exit = false; - thread = new Thread("Periodic task", body); + exit = true; } ~Periodic() { - exit = true; - thread.join(); + if (!exit) { + exit = true; + thread.join(); + } } protected abstract void task(); + public void start() { + if (exit) { + exit = false; + thread = new Thread("Periodic task", body); + } + } + private void body() { while (!exit) { task();