diff --git a/include/aikido/util/ExecutorThread.hpp b/include/aikido/util/ExecutorThread.hpp index 35424f7b57..f39b72760b 100644 --- a/include/aikido/util/ExecutorThread.hpp +++ b/include/aikido/util/ExecutorThread.hpp @@ -25,18 +25,18 @@ class ExecutorThread final public: /// Constructs from callback and period. The thread begins execution /// immediately upon construction. - /// \param[in] callback - /// \param[in] period + /// \param[in] callback Callback to be repeatedly executed by the thread. + /// \param[in] period The period of calling the callback. template ExecutorThread(std::function callback, const Duration& period); - /// Default destructor. The thread is stopped as ExecutorThread is destructed. + /// Default destructor. The thread stops as ExecutorThread is destructed. ~ExecutorThread(); /// Returns true if the thread is running. bool isRunning() const; - /// Stops the thread. It is safe to call this function even when the thread is + /// Stops the thread. It is safe to call this function even when the thread /// already stopped. void stop(); diff --git a/src/util/ExecutorThread.cpp b/src/util/ExecutorThread.cpp index a187179a7c..25cb4ccfb4 100644 --- a/src/util/ExecutorThread.cpp +++ b/src/util/ExecutorThread.cpp @@ -39,7 +39,12 @@ void ExecutorThread::spin() catch (const std::exception& e) { std::cerr << "Exception thrown by callback: " << e.what() << std::endl; + // TODO: We should find another way to handle this error, so we don't + // print directly to std::cerr. Unfortunately, we don't have a better + // solution yet since Aikido doesn't use any particular logging framework. mIsRunning.store(false); + + break; } currentTime += mPeriod; diff --git a/tests/util/test_Executor.cpp b/tests/util/test_Executor.cpp index 53da70b6ff..7c98308852 100644 --- a/tests/util/test_Executor.cpp +++ b/tests/util/test_Executor.cpp @@ -41,3 +41,14 @@ TEST(ExecutorThread, Execute) exec.stop(); EXPECT_TRUE(!exec.isRunning()); } + +//============================================================================== +TEST(ExecutorThread, ExceptionThrownByCallback) +{ + ExecutorThread exec( + []() { throw std::exception(); }, std::chrono::milliseconds(1)); + + std::this_thread::sleep_for(std::chrono::seconds(3)); + + EXPECT_TRUE(!exec.isRunning()); +}