diff --git a/lib/core/scheduler.cpp b/lib/core/scheduler.cpp index 3fbb61f4..b1416a3f 100644 --- a/lib/core/scheduler.cpp +++ b/lib/core/scheduler.cpp @@ -30,7 +30,7 @@ core::Result Scheduler::run() return result; } -void Scheduler::addTask(std::function task, uint32_t delay) +void Scheduler::addTask(uint32_t delay, std::function task) { const auto execution_timepoint = std::chrono::time_point_cast(time_.now()) diff --git a/lib/core/scheduler.hpp b/lib/core/scheduler.hpp index 48c149b0..ba84d9ef 100644 --- a/lib/core/scheduler.hpp +++ b/lib/core/scheduler.hpp @@ -29,7 +29,7 @@ class Scheduler { * @param task a function that returns a Result * @param delay the minimum delay in microseconds before the task can called */ - void addTask(std::function task, uint32_t delay); + void addTask(uint32_t delay, std::function task); private: core::ILogger &logger_; diff --git a/test/core/scheduler.cpp b/test/core/scheduler.cpp index 6c88ebce..229a24ac 100644 --- a/test/core/scheduler.cpp +++ b/test/core/scheduler.cpp @@ -20,12 +20,10 @@ TEST(Scheduler, immediateTask) core::Logger logger("test", core::LogLevel::kDebug, manual_time); core::Scheduler scheduler(logger, manual_time); bool task_called = false; - scheduler.addTask( - [&task_called]() { - task_called = true; - return core::Result::kSuccess; - }, - 0); + scheduler.addTask(0, [&task_called]() { + task_called = true; + return core::Result::kSuccess; + }); ASSERT_EQ(scheduler.run(), core::Result::kSuccess); ASSERT_TRUE(task_called); } @@ -36,12 +34,10 @@ TEST(Scheduler, delayedTask) core::Logger logger("test", core::LogLevel::kDebug, manual_time); core::Scheduler scheduler(logger, manual_time); bool task_called = false; - scheduler.addTask( - [&task_called]() { - task_called = true; - return core::Result::kSuccess; - }, - 1000); + scheduler.addTask(1000, [&task_called]() { + task_called = true; + return core::Result::kSuccess; + }); ASSERT_EQ(scheduler.run(), core::Result::kSuccess); ASSERT_FALSE(task_called); manual_time.set_time(std::chrono::system_clock::from_time_t(1)); @@ -55,12 +51,10 @@ TEST(Scheduler, failingTask) core::Logger logger("test", core::LogLevel::kDebug, manual_time); core::Scheduler scheduler(logger, manual_time); bool task_called = false; - scheduler.addTask( - [&task_called]() { - task_called = true; - return core::Result::kFailure; - }, - 0); + scheduler.addTask(0, [&task_called]() { + task_called = true; + return core::Result::kFailure; + }); ASSERT_EQ(scheduler.run(), core::Result::kFailure); ASSERT_TRUE(task_called); } @@ -72,18 +66,14 @@ TEST(Scheduler, multipleTasksCorrectOrder) core::Scheduler scheduler(logger, manual_time); bool task1_called = false; bool task2_called = false; - scheduler.addTask( - [&task1_called]() { - task1_called = true; - return core::Result::kSuccess; - }, - 0); - scheduler.addTask( - [&task2_called]() { - task2_called = true; - return core::Result::kSuccess; - }, - 0); + scheduler.addTask(0, [&task1_called]() { + task1_called = true; + return core::Result::kSuccess; + }); + scheduler.addTask(0, [&task2_called]() { + task2_called = true; + return core::Result::kSuccess; + }); manual_time.set_time(std::chrono::system_clock::from_time_t(1)); ASSERT_EQ(scheduler.run(), core::Result::kSuccess); ASSERT_TRUE(task1_called);