diff --git a/emper/io/Future.hpp b/emper/io/Future.hpp index 2f8afc7f382bc2304eee3b6bda0a207d0d94c328..4bac70ce22cf656239af8e6d1e6a41e76e2425c9 100644 --- a/emper/io/Future.hpp +++ b/emper/io/Future.hpp @@ -56,10 +56,7 @@ class Future : public Logger<LogSubsystem::IO> { public: workeraffinity_t affinity; - // store callback via copy CallbackInternal(Callback callback) : callback(std::move(callback)) {} - // store callback via move - CallbackInternal(const Callback&& callback) : callback(callback) {} void operator()(const int32_t& res) { callback(res); } }; @@ -247,32 +244,17 @@ class Future : public Logger<LogSubsystem::IO> { this->dependency = &dependency; } - private: - inline void setCallback(CallbackInternal* callback) { - if (unlikely(this->callback)) { - delete this->callback; - } - - this->callback = callback; - } - - public: /* * @brief register a callback which is executed in a new Fiber on completion * * @param callback Callback reference which is copied and executed on completion. * It gets passed the value causing the completion. */ - inline void setCallback(const Callback& callback) { setCallback(new CallbackInternal(callback)); } - - /* - * @brief register a callback which is executed in a new Fiber on completion - * - * @param callback Callback rvalue which gets moved and executed on completion. - * It gets passed the value causing the completion. - */ - inline void setCallback(const Callback&& callback) { - setCallback(new CallbackInternal(callback)); + inline void setCallback(const Callback& callback) { + if (unlikely(this->callback)) { + delete this->callback; + } + this->callback = new CallbackInternal(callback); } /* diff --git a/tests/io/FutureCallbackTest.cpp b/tests/io/FutureCallbackTest.cpp index 4e7e85bb2a903c6d0ac3ef138239968a08564813..a4a1dcd229d673d72302d6c5b588fa63c8822209 100644 --- a/tests/io/FutureCallbackTest.cpp +++ b/tests/io/FutureCallbackTest.cpp @@ -10,17 +10,15 @@ using emper::io::AlarmFuture; using emper::io::Future; -void callback(int32_t res, BPS& bps) { - assert(res == -ETIME); - bps.signal(); -} - void emperTest() { AlarmFuture::Timespec ts = {.tv_sec = 1, .tv_nsec = 0}; AlarmFuture alarm(ts); BPS bps; - alarm.setCallback(Future::Callback([&bps](int32_t res) { callback(res, bps); })); + alarm.setCallback([&bps](int32_t res) { + assert(res == -ETIME); + bps.signal(); + }); alarm.submit(); // wait till the callback was executed