Skip to content

Commit

Permalink
added new API to get the threads and also the progress boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
saikishor committed Jun 13, 2024
1 parent 9695ad6 commit 28bb919
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/realtime_tools/async_function_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ class AsyncFunctionHandler
*/
bool is_stopped() const { return async_update_stop_; }

/// Get the async update thread
/**
* @return The async update thread
*/
std::thread & get_thread() { return thread_; }

/// Check if the async update method is in progress
/**
* @return True if the async update method is in progress, false otherwise
*/
bool is_trigger_cycle_in_progress() const { return trigger_in_progress_; }

/// Stops the async update thread
/**
* If the async method is running, it will notify the async thread to stop and then joins the
Expand Down
6 changes: 6 additions & 0 deletions test/test_async_function_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ TEST_F(AsyncFunctionHandlerTest, check_triggering)
ASSERT_TRUE(async_class.get_handler().is_initialized());
ASSERT_TRUE(async_class.get_handler().is_running());
ASSERT_FALSE(async_class.get_handler().is_stopped());
ASSERT_TRUE(async_class.get_handler().get_thread().joinable());
ASSERT_TRUE(async_class.get_handler().is_trigger_cycle_in_progress());
async_class.get_handler().wait_for_trigger_cycle_to_finish();
ASSERT_FALSE(async_class.get_handler().is_trigger_cycle_in_progress());
ASSERT_EQ(async_class.get_counter(), 1);

// Trigger one more cycle
Expand Down Expand Up @@ -164,6 +167,7 @@ TEST_F(AsyncFunctionHandlerTest, trigger_for_several_cycles)
ASSERT_TRUE(async_class.get_handler().is_running());
ASSERT_FALSE(async_class.get_handler().is_stopped());
async_class.get_handler().wait_for_trigger_cycle_to_finish();
ASSERT_FALSE(async_class.get_handler().is_trigger_cycle_in_progress());
ASSERT_EQ(async_class.get_counter(), i - missed_triggers);
} else {
missed_triggers++;
Expand Down Expand Up @@ -204,10 +208,12 @@ TEST_F(AsyncFunctionHandlerTest, test_with_deactivate_and_activate_cycles)
const auto trigger_status = async_class.trigger();
ASSERT_TRUE(trigger_status.first);
ASSERT_EQ(realtime_tools::return_type::OK, trigger_status.second);
ASSERT_TRUE(async_class.get_handler().is_trigger_cycle_in_progress());
ASSERT_TRUE(async_class.get_handler().is_initialized());
ASSERT_TRUE(async_class.get_handler().is_running());
ASSERT_FALSE(async_class.get_handler().is_stopped());
async_class.get_handler().wait_for_trigger_cycle_to_finish();
ASSERT_FALSE(async_class.get_handler().is_trigger_cycle_in_progress());
ASSERT_EQ(async_class.get_counter(), i);
std::this_thread::sleep_for(std::chrono::microseconds(1));
}
Expand Down

0 comments on commit 28bb919

Please sign in to comment.