Horizon Official Technical Documentation
TaskSchedulingTest.cpp File Reference
#include <boost/test/unit_test.hpp>
#include <cstring>
#include <thread>
#include "Utility/TaskScheduler.hpp"
+ Include dependency graph for TaskSchedulingTest.cpp:

Macros

#define BOOST_TEST_MODULE   "TaskSchedulingTest"
 
#define MAX_COUNT   3
 
#define INTERVAL   5
 

Functions

 BOOST_AUTO_TEST_CASE (TaskSchedulingTest)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   "TaskSchedulingTest"

◆ INTERVAL

#define INTERVAL   5

◆ MAX_COUNT

#define MAX_COUNT   3

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( TaskSchedulingTest  )
43{
44 TaskScheduler task_scheduler;
45 int count = 0;
46
47 printf("Executing tasks every %d seconds...\n", INTERVAL);
48
49 task_scheduler.Schedule(Seconds(INTERVAL), [this, &count] (TaskContext context) {
50 printf("task executed %d times\n", ++count);
51 if (count < MAX_COUNT)
52 context.Repeat(Seconds(INTERVAL));
53 });
54
55 while (true && count < MAX_COUNT) {
56 uint32_t diff = 500;
57 task_scheduler.Update();
58 std::this_thread::sleep_for(std::chrono::milliseconds(diff));
59 }
60}
std::chrono::seconds Seconds
Seconds shorthand typedef.
Definition: TaskScheduler.hpp:34
#define INTERVAL
Definition: TaskSchedulingTest.cpp:40
#define MAX_COUNT
Definition: TaskSchedulingTest.cpp:39
Definition: TaskScheduler.hpp:487
TaskContext & Repeat(std::chrono::duration< _Rep, _Period > const &duration)
Repeats the event and sets a new duration. std::chrono::seconds(5) for example. This will consume the...
Definition: TaskScheduler.hpp:560
The TaskScheduler class provides the ability to schedule std::function's in the near future....
Definition: TaskScheduler.hpp:58
TaskScheduler & Schedule(std::chrono::duration< _Rep, _Period > const &time, task_handler_t const &task)
Schedule an event with a fixed rate. Never call this from within a task context! Use TaskContext::Sch...
Definition: TaskScheduler.hpp:278
TaskScheduler & Update(success_t const &callback=EmptyCallback)
Update the scheduler to the current time. Calls the optional callback on successfully finish.
Definition: TaskScheduler.cpp:25
size_t count(GridTypeListContainer< SPECIFIC_TYPE > const &elements, SPECIFIC_TYPE *)
Definition: GridReferenceContainer.hpp:100

References GridTypeListIterator::count(), INTERVAL, MAX_COUNT, TaskContext::Repeat(), TaskScheduler::Schedule(), and TaskScheduler::Update().

+ Here is the call graph for this function: