diff options
author | Andrew <47818697+Nyeriah@users.noreply.github.com> | 2024-11-24 12:02:56 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-24 12:02:56 -0300 |
commit | ab7f49b220f9dd3cc62fbeb7015df2d76e53301b (patch) | |
tree | c56d355c3025a76d08839f83d8b1e3c83f8002ef /src/common/Utilities/TaskScheduler.cpp | |
parent | 735a5a5037cd685e0c5246c793fe7159745d836e (diff) |
feat(Core/Scripting): Implement TaskScheduler GetNextGroupOccurrence() (#20714)
Diffstat (limited to 'src/common/Utilities/TaskScheduler.cpp')
-rw-r--r-- | src/common/Utilities/TaskScheduler.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/common/Utilities/TaskScheduler.cpp b/src/common/Utilities/TaskScheduler.cpp index 1e4e0222da..6f8978f3c8 100644 --- a/src/common/Utilities/TaskScheduler.cpp +++ b/src/common/Utilities/TaskScheduler.cpp @@ -124,6 +124,11 @@ bool TaskScheduler::IsGroupScheduled(group_t const group) return _task_holder.IsGroupQueued(group); } +Milliseconds TaskScheduler::GetNextGroupOcurrence(group_t const group) const +{ + return std::chrono::duration_cast<std::chrono::milliseconds>(_task_holder.GetNextGroupOcurrence(group) - clock_t::now()); +} + void TaskScheduler::TaskQueue::Push(TaskContainer&& task) { container.insert(task); @@ -189,6 +194,18 @@ bool TaskScheduler::TaskQueue::IsGroupQueued(group_t const group) return false; } +TaskScheduler::timepoint_t TaskScheduler::TaskQueue::GetNextGroupOcurrence(group_t const group) const +{ + TaskScheduler::timepoint_t next = TaskScheduler::timepoint_t::max(); + for (auto const& task : container) + { + if (task->IsInGroup(group) && task->_end < next) + next = task->_end; + } + + return next; +} + bool TaskScheduler::TaskQueue::IsEmpty() const { return container.empty(); @@ -231,6 +248,11 @@ TaskScheduler::repeated_t TaskContext::GetRepeatCounter() const return _task->_repeated; } +TaskScheduler::timepoint_t TaskContext::GetNextOcurrence() const +{ + return _task->_end; +} + TaskContext& TaskContext::Async(std::function<void()> const& callable) { return Dispatch(std::bind(&TaskScheduler::Async, std::placeholders::_1, callable)); |