Skip to content

Commit

Permalink
reorder args
Browse files Browse the repository at this point in the history
  • Loading branch information
TomLonergan03 committed Aug 19, 2023
1 parent 8d5a7bf commit b9677a3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lib/core/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ core::Result Scheduler::run()
return result;
}

void Scheduler::addTask(std::function<core::Result(void)> task, uint32_t delay)
void Scheduler::addTask(uint32_t delay, std::function<core::Result(void)> task)
{
const auto execution_timepoint
= std::chrono::time_point_cast<std::chrono::microseconds>(time_.now())
Expand Down
2 changes: 1 addition & 1 deletion lib/core/scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<core::Result(void)> task, uint32_t delay);
void addTask(uint32_t delay, std::function<core::Result(void)> task);

private:
core::ILogger &logger_;
Expand Down
50 changes: 20 additions & 30 deletions test/core/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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));
Expand All @@ -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);
}
Expand All @@ -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);
Expand Down

0 comments on commit b9677a3

Please sign in to comment.