Skip to content
This repository was archived by the owner on Apr 3, 2025. It is now read-only.

Commit 1807afe

Browse files
author
Luc Sinet
committed
develop #comment Use nanoseconds as default duration (Scheduler).
- Avoid useless copies (TimedTask).
1 parent 21aedb0 commit 1807afe

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

include/TaskManager/Scheduler.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
namespace Task {
1717

18+
using Duration = std::chrono::nanoseconds;
19+
1820
//! The task scheduler.
1921
class Scheduler {
2022
public:
@@ -33,7 +35,7 @@ class Scheduler {
3335
//! @param delay The delay to wait before executing the task.
3436
//! @param function The function to execute.
3537
//! @param args the parameters to pass to the function.
36-
template <typename Duration, class F, class... Args>
38+
template <class F, class... Args>
3739
auto scheduleIn(const std::string& id, Duration delay, F&& function, Args&&... args) {
3840
return this->scheduleAt(id, Detail::Clock::now() + delay, std::forward<F>(function), std::forward<Args>(args)...);
3941
}
@@ -73,7 +75,7 @@ class Scheduler {
7375
//! @param delay The minimum duration separating two executions.
7476
//! @param function The function to execute.
7577
//! @param args the parameters to pass to the function.
76-
template <typename Duration, class F, class... Args>
78+
template <class F, class... Args>
7779
void scheduleEvery(const std::string& id, Duration delay, F&& function, Args&&... args) {
7880
auto task = std::bind(std::forward<F>(function), std::forward<Args>(args)...);
7981
const auto hash = _hasher(id);

include/TaskManager/detail/Task.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <chrono>
55
#include <functional>
6+
#include <utility>
67

78
namespace Task {
89
namespace Detail {
@@ -13,8 +14,8 @@ using Timepoint = Clock::time_point;
1314

1415
class TimedTask {
1516
public:
16-
TimedTask(Task functor, Timepoint timepoint)
17-
: _functor(functor)
17+
TimedTask(Task functor, const Timepoint& timepoint)
18+
: _functor(std::move(functor))
1819
, _timepoint(timepoint) {}
1920

2021
const Timepoint& timepoint() const {

0 commit comments

Comments
 (0)