Horizon Official Technical Documentation
TaskContext Class Reference

#include <TaskScheduler.hpp>

Public Member Functions

 TaskContext ()
 
 TaskContext (TaskScheduler::TaskContainer &&task, std::weak_ptr< TaskScheduler > &&owner)
 
 TaskContext (TaskContext &&right)
 
TaskContextoperator= (TaskContext &&right)
 
bool IsExpired () const
 Returns true if the owner was deallocated and this context has expired. More...
 
bool IsInGroup (TaskScheduler::group_t const group) const
 Returns true if the event is in the given group. More...
 
TaskContextSetGroup (TaskScheduler::group_t const group)
 Sets the event in the given group. More...
 
TaskContextClearGroup ()
 Removes the group from the event. More...
 
TaskScheduler::repeated_t GetRepeatCounter () const
 Returns the repeat counter which increases every time the task is repeated. More...
 
template<typename _Rep , typename _Period >
TaskContextRepeat (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 task context, its not possible to repeat the task again from the same task context! More...
 
TaskContextRepeat ()
 Repeats the event with the same duration. This will consume the task context, its not possible to repeat the task again from the same task context! More...
 
template<typename _RepLeft , typename _PeriodLeft , typename _RepRight , typename _PeriodRight >
TaskContextRepeat (std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max)
 Repeats the event and set a new duration that is randomized between min and max. std::chrono::seconds(5) for example. This will consume the task context, its not possible to repeat the task again from the same task context! More...
 
TaskContextAsync (std::function< void()> const &callable)
 Schedule a callable function that is executed at the next update tick from within the context. Its safe to modify the TaskScheduler from within the callable. More...
 
template<typename _Rep , typename _Period >
TaskContextSchedule (std::chrono::duration< _Rep, _Period > const &time, TaskScheduler::task_handler_t const &task)
 Schedule an event with a fixed rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick. More...
 
template<typename _Rep , typename _Period >
TaskContextSchedule (std::chrono::duration< _Rep, _Period > const &time, TaskScheduler::group_t const group, TaskScheduler::task_handler_t const &task)
 Schedule an event with a fixed rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick. More...
 
template<typename _RepLeft , typename _PeriodLeft , typename _RepRight , typename _PeriodRight >
TaskContextSchedule (std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max, TaskScheduler::task_handler_t const &task)
 Schedule an event with a randomized rate between min and max rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick. More...
 
template<typename _RepLeft , typename _PeriodLeft , typename _RepRight , typename _PeriodRight >
TaskContextSchedule (std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max, TaskScheduler::group_t const group, TaskScheduler::task_handler_t const &task)
 Schedule an event with a randomized rate between min and max rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick. More...
 
TaskContextCancelAll ()
 Cancels all tasks from within the context. More...
 
TaskContextCancelGroup (TaskScheduler::group_t const group)
 Cancel all tasks of a single group from within the context. More...
 
TaskContextCancelGroupsOf (std::vector< TaskScheduler::group_t > const &groups)
 Cancels all groups in the given std::vector from within the context. Hint: Use std::initializer_list for this: "{1, 2, 3, 4}". More...
 
template<typename _Rep , typename _Period >
TaskContextDelayAll (std::chrono::duration< _Rep, _Period > const &duration)
 Delays all tasks with the given duration from within the context. More...
 
template<typename _RepLeft , typename _PeriodLeft , typename _RepRight , typename _PeriodRight >
TaskContextDelayAll (std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max)
 Delays all tasks with a random duration between min and max from within the context. More...
 
template<typename _Rep , typename _Period >
TaskContextDelayGroup (TaskScheduler::group_t const group, std::chrono::duration< _Rep, _Period > const &duration)
 Delays all tasks of a group with the given duration from within the context. More...
 
template<typename _RepLeft , typename _PeriodLeft , typename _RepRight , typename _PeriodRight >
TaskContextDelayGroup (TaskScheduler::group_t const group, std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max)
 Delays all tasks of a group with a random duration between min and max from within the context. More...
 
template<typename _Rep , typename _Period >
TaskContextRescheduleAll (std::chrono::duration< _Rep, _Period > const &duration)
 Reschedule all tasks with the given duration. More...
 
template<typename _RepLeft , typename _PeriodLeft , typename _RepRight , typename _PeriodRight >
TaskContextRescheduleAll (std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max)
 Reschedule all tasks with a random duration between min and max. More...
 
template<typename _Rep , typename _Period >
TaskContextRescheduleGroup (TaskScheduler::group_t const group, std::chrono::duration< _Rep, _Period > const &duration)
 Reschedule all tasks of a group with the given duration. More...
 
template<typename _RepLeft , typename _PeriodLeft , typename _RepRight , typename _PeriodRight >
TaskContextRescheduleGroup (TaskScheduler::group_t const group, std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max)
 Reschedule all tasks of a group with a random duration between min and max. More...
 

Private Member Functions

TaskContextDispatch (std::function< TaskScheduler &(TaskScheduler &)> const &apply)
 Dispatches an action safe on the TaskScheduler. More...
 
TaskContextoperator= (TaskContext const &right)
 
 TaskContext (TaskContext const &right)
 
void ThrowOnConsumed () const
 Throws std::logic_error if the task was consumed already. More...
 
void Invoke ()
 Invokes the associated hook of the task. More...
 

Private Attributes

TaskScheduler::TaskContainer _task
 Associated task. More...
 
std::weak_ptr< TaskScheduler_owner
 Owner. More...
 
std::shared_ptr< bool > _consumed
 Marks the task as consumed. More...
 

Friends

class TaskScheduler
 

Constructor & Destructor Documentation

◆ TaskContext() [1/4]

TaskContext::TaskContext ( TaskContext const &  right)
inlineprivate
515 : _task(right._task), _owner(right._owner), _consumed(right._consumed) { }
TaskScheduler::TaskContainer _task
Associated task.
Definition: TaskScheduler.hpp:491
std::weak_ptr< TaskScheduler > _owner
Owner.
Definition: TaskScheduler.hpp:494
std::shared_ptr< bool > _consumed
Marks the task as consumed.
Definition: TaskScheduler.hpp:497

◆ TaskContext() [2/4]

TaskContext::TaskContext ( )
inline
520 : _task(), _owner(), _consumed(std::make_shared<bool>(true)) { }

◆ TaskContext() [3/4]

TaskContext::TaskContext ( TaskScheduler::TaskContainer &&  task,
std::weak_ptr< TaskScheduler > &&  owner 
)
inlineexplicit
524 : _task(task), _owner(owner), _consumed(std::make_shared<bool>(false)) { }

◆ TaskContext() [4/4]

TaskContext::TaskContext ( TaskContext &&  right)
inline
528 : _task(std::move(right._task)), _owner(std::move(right._owner)),
529 _consumed(std::move(right._consumed)) { }

Member Function Documentation

◆ Async()

TaskContext & TaskContext::Async ( std::function< void()> const &  callable)

Schedule a callable function that is executed at the next update tick from within the context. Its safe to modify the TaskScheduler from within the callable.

218{
219 return Dispatch(std::bind(&TaskScheduler::Async, std::placeholders::_1, callable));
220}
TaskContext & Dispatch(std::function< TaskScheduler &(TaskScheduler &)> const &apply)
Dispatches an action safe on the TaskScheduler.
Definition: TaskScheduler.cpp:182
TaskScheduler & Async(std::function< void()> const &callable)
Schedule an callable function that is executed at the next update tick. Its safe to modify the TaskSc...
Definition: TaskScheduler.cpp:37

References TaskScheduler::Async(), and TaskScheduler::Dispatch().

+ Here is the call graph for this function:

◆ CancelAll()

TaskContext & TaskContext::CancelAll ( )

Cancels all tasks from within the context.

223{
224 return Dispatch(std::bind(&TaskScheduler::CancelAll, std::placeholders::_1));
225}
TaskScheduler & CancelAll()
Cancels all tasks. Never call this from within a task context! Use TaskContext::CancelAll instead!
Definition: TaskScheduler.cpp:43

References TaskScheduler::CancelAll(), and TaskScheduler::Dispatch().

+ Here is the call graph for this function:

◆ CancelGroup()

TaskContext & TaskContext::CancelGroup ( TaskScheduler::group_t const  group)

Cancel all tasks of a single group from within the context.

228{
229 return Dispatch(std::bind(&TaskScheduler::CancelGroup, std::placeholders::_1, group));
230}
TaskScheduler & CancelGroup(group_t const group)
Cancel all tasks of a single group. Never call this from within a task context! Use TaskContext::Canc...
Definition: TaskScheduler.cpp:51

References TaskScheduler::CancelGroup(), and TaskScheduler::Dispatch().

+ Here is the call graph for this function:

◆ CancelGroupsOf()

TaskContext & TaskContext::CancelGroupsOf ( std::vector< TaskScheduler::group_t > const &  groups)

Cancels all groups in the given std::vector from within the context. Hint: Use std::initializer_list for this: "{1, 2, 3, 4}".

233{
234 return Dispatch(std::bind(&TaskScheduler::CancelGroupsOf, std::placeholders::_1, std::cref(groups)));
235}
TaskScheduler & CancelGroupsOf(std::vector< group_t > const &groups)
Cancels all groups in the given std::vector. Hint: Use std::initializer_list for this: "{1,...
Definition: TaskScheduler.cpp:59

References TaskScheduler::CancelGroupsOf(), and TaskScheduler::Dispatch().

+ Here is the call graph for this function:

◆ ClearGroup()

TaskContext & TaskContext::ClearGroup ( )

Removes the group from the event.

207{
208 _task->_group = nullptr;
209 return *this;
210}

◆ DelayAll() [1/2]

template<typename _Rep , typename _Period >
TaskContext & TaskContext::DelayAll ( std::chrono::duration< _Rep, _Period > const &  duration)
inline

Delays all tasks with the given duration from within the context.

666 {
667 return Dispatch(std::bind(&TaskScheduler::DelayAll<_Rep, _Period>, std::placeholders::_1, duration));
668 }

References Dispatch().

Referenced by DelayAll().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DelayAll() [2/2]

template<typename _RepLeft , typename _PeriodLeft , typename _RepRight , typename _PeriodRight >
TaskContext & TaskContext::DelayAll ( std::chrono::duration< _RepLeft, _PeriodLeft > const &  min,
std::chrono::duration< _RepRight, _PeriodRight > const &  max 
)
inline

Delays all tasks with a random duration between min and max from within the context.

674 {
676 }
TaskContext & DelayAll(std::chrono::duration< _Rep, _Period > const &duration)
Delays all tasks with the given duration from within the context.
Definition: TaskScheduler.hpp:665
static std::chrono::duration< _RepLeft, _PeriodLeft > RandomDurationBetween(std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max)
Definition: TaskScheduler.hpp:456

References DelayAll(), and TaskScheduler::RandomDurationBetween().

+ Here is the call graph for this function:

◆ DelayGroup() [1/2]

template<typename _Rep , typename _Period >
TaskContext & TaskContext::DelayGroup ( TaskScheduler::group_t const  group,
std::chrono::duration< _Rep, _Period > const &  duration 
)
inline

Delays all tasks of a group with the given duration from within the context.

681 {
682 return Dispatch(std::bind(&TaskScheduler::DelayGroup<_Rep, _Period>, std::placeholders::_1, group, duration));
683 }

References Dispatch().

Referenced by DelayGroup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DelayGroup() [2/2]

template<typename _RepLeft , typename _PeriodLeft , typename _RepRight , typename _PeriodRight >
TaskContext & TaskContext::DelayGroup ( TaskScheduler::group_t const  group,
std::chrono::duration< _RepLeft, _PeriodLeft > const &  min,
std::chrono::duration< _RepRight, _PeriodRight > const &  max 
)
inline

Delays all tasks of a group with a random duration between min and max from within the context.

690 {
691 return DelayGroup(group, TaskScheduler::RandomDurationBetween(min, max));
692 }
TaskContext & DelayGroup(TaskScheduler::group_t const group, std::chrono::duration< _Rep, _Period > const &duration)
Delays all tasks of a group with the given duration from within the context.
Definition: TaskScheduler.hpp:680

References DelayGroup(), and TaskScheduler::RandomDurationBetween().

+ Here is the call graph for this function:

◆ Dispatch()

TaskContext & TaskContext::Dispatch ( std::function< TaskScheduler &(TaskScheduler &)> const &  apply)
private

Dispatches an action safe on the TaskScheduler.

183{
184 if (auto const owner = _owner.lock())
185 apply(*owner);
186
187 return *this;
188}
void apply(T *val)
Definition: ByteConverter.hpp:48

References ByteConverter::apply().

Referenced by DelayAll(), DelayGroup(), Repeat(), RescheduleAll(), RescheduleGroup(), and Schedule().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetRepeatCounter()

TaskScheduler::repeated_t TaskContext::GetRepeatCounter ( ) const

Returns the repeat counter which increases every time the task is repeated.

213{
214 return _task->_repeated;
215}

◆ Invoke()

void TaskContext::Invoke ( )
private

Invokes the associated hook of the task.

245{
246 _task->_task(*this);
247}

Referenced by TaskScheduler::Dispatch().

+ Here is the caller graph for this function:

◆ IsExpired()

bool TaskContext::IsExpired ( ) const

Returns true if the owner was deallocated and this context has expired.

191{
192 return _owner.expired();
193}

◆ IsInGroup()

bool TaskContext::IsInGroup ( TaskScheduler::group_t const  group) const

Returns true if the event is in the given group.

196{
197 return _task->IsInGroup(group);
198}

◆ operator=() [1/2]

TaskContext & TaskContext::operator= ( TaskContext &&  right)
inline
533 {
534 _task = std::move(right._task);
535 _owner = std::move(right._owner);
536 _consumed = std::move(right._consumed);
537 return *this;
538 }

References _consumed, _owner, and _task.

◆ operator=() [2/2]

TaskContext & TaskContext::operator= ( TaskContext const &  right)
inlineprivate
505 {
506 _task = right._task;
507 _owner = right._owner;
508 _consumed = right._consumed;
509 return *this;
510 }

References _consumed, _owner, and _task.

◆ Repeat() [1/3]

TaskContext & TaskContext::Repeat ( )
inline

Repeats the event with the same duration. This will consume the task context, its not possible to repeat the task again from the same task context!

570 {
572
573 // Set new duration, in-context timing and increment repeat counter
574 _task->_end += _task->_duration_calculator();
575 _task->_repeated += 1;
576 (*_consumed) = true;
577 return Dispatch(std::bind(&TaskScheduler::InsertTask, std::placeholders::_1, std::cref(_task)));
578 }
void ThrowOnConsumed() const
Throws std::logic_error if the task was consumed already.
Definition: TaskScheduler.cpp:237
TaskScheduler & InsertTask(TaskContainer task)
Insert a new task to the enqueued tasks.
Definition: TaskScheduler.cpp:67

References _task, Dispatch(), TaskScheduler::InsertTask(), and ThrowOnConsumed().

Referenced by Repeat().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Repeat() [2/3]

template<typename _Rep , typename _Period >
TaskContext & TaskContext::Repeat ( std::chrono::duration< _Rep, _Period > const &  duration)
inline

Repeats the event and sets a new duration. std::chrono::seconds(5) for example. This will consume the task context, its not possible to repeat the task again from the same task context!

561 {
562 _task->_duration_calculator = TaskScheduler::MakeDurationCalculator(duration);
563 return Repeat();
564 }
TaskContext & Repeat()
Repeats the event with the same duration. This will consume the task context, its not possible to rep...
Definition: TaskScheduler.hpp:569
static duration_calculator_t MakeDurationCalculator(std::chrono::duration< _Rep, _Period > const &duration)
Definition: TaskScheduler.hpp:70

References _task, TaskScheduler::MakeDurationCalculator(), and Repeat().

Referenced by Horizon::Zone::Unit::attack(), BOOST_AUTO_TEST_CASE(), Horizon::Zone::Units::Monster::initialize(), Horizon::Zone::ZoneKernel::initialize(), Horizon::Auth::AuthServer::initialize(), Horizon::Char::CharServer::initialize(), Horizon::Zone::Unit::status_effect_start(), and Horizon::Zone::Unit::walk().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Repeat() [3/3]

template<typename _RepLeft , typename _PeriodLeft , typename _RepRight , typename _PeriodRight >
TaskContext & TaskContext::Repeat ( std::chrono::duration< _RepLeft, _PeriodLeft > const &  min,
std::chrono::duration< _RepRight, _PeriodRight > const &  max 
)
inline

Repeats the event and set a new duration that is randomized between min and max. std::chrono::seconds(5) for example. This will consume the task context, its not possible to repeat the task again from the same task context!

587 {
588 _task->_duration_calculator = TaskScheduler::MakeDurationCalculator(min, max);
589 return Repeat();
590 }

References _task, TaskScheduler::MakeDurationCalculator(), and Repeat().

+ Here is the call graph for this function:

◆ RescheduleAll() [1/2]

template<typename _Rep , typename _Period >
TaskContext & TaskContext::RescheduleAll ( std::chrono::duration< _Rep, _Period > const &  duration)
inline

Reschedule all tasks with the given duration.

697 {
698 return Dispatch(std::bind(&TaskScheduler::RescheduleAt, std::placeholders::_1, _task->_end + duration));
699 }
TaskScheduler & RescheduleAt(timepoint_t const &end)
Definition: TaskScheduler.hpp:432

References _task, Dispatch(), and TaskScheduler::RescheduleAt().

Referenced by RescheduleAll().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RescheduleAll() [2/2]

template<typename _RepLeft , typename _PeriodLeft , typename _RepRight , typename _PeriodRight >
TaskContext & TaskContext::RescheduleAll ( std::chrono::duration< _RepLeft, _PeriodLeft > const &  min,
std::chrono::duration< _RepRight, _PeriodRight > const &  max 
)
inline

Reschedule all tasks with a random duration between min and max.

705 {
707 }
TaskContext & RescheduleAll(std::chrono::duration< _Rep, _Period > const &duration)
Reschedule all tasks with the given duration.
Definition: TaskScheduler.hpp:696

References TaskScheduler::RandomDurationBetween(), and RescheduleAll().

+ Here is the call graph for this function:

◆ RescheduleGroup() [1/2]

template<typename _Rep , typename _Period >
TaskContext & TaskContext::RescheduleGroup ( TaskScheduler::group_t const  group,
std::chrono::duration< _Rep, _Period > const &  duration 
)
inline

Reschedule all tasks of a group with the given duration.

712 {
713 return Dispatch(std::bind(&TaskScheduler::RescheduleAtWithPredicate, std::placeholders::_1, _task->_end + duration,
714 [&](TaskScheduler::TaskContainer const& task)
715 {
716 return task->IsInGroup(group);
717 }));
718 }
TaskScheduler & RescheduleAtWithPredicate(timepoint_t const &end, std::function< bool(TaskContainer const &)> const &predicate)
Reschedule all tasks with a given duration relative to the given time.
Definition: TaskScheduler.hpp:438
std::shared_ptr< Task > TaskContainer
Definition: TaskScheduler.hpp:165

References _task, Dispatch(), and TaskScheduler::RescheduleAtWithPredicate().

Referenced by RescheduleGroup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RescheduleGroup() [2/2]

template<typename _RepLeft , typename _PeriodLeft , typename _RepRight , typename _PeriodRight >
TaskContext & TaskContext::RescheduleGroup ( TaskScheduler::group_t const  group,
std::chrono::duration< _RepLeft, _PeriodLeft > const &  min,
std::chrono::duration< _RepRight, _PeriodRight > const &  max 
)
inline

Reschedule all tasks of a group with a random duration between min and max.

725 {
727 }
TaskContext & RescheduleGroup(TaskScheduler::group_t const group, std::chrono::duration< _Rep, _Period > const &duration)
Reschedule all tasks of a group with the given duration.
Definition: TaskScheduler.hpp:711

References TaskScheduler::RandomDurationBetween(), and RescheduleGroup().

+ Here is the call graph for this function:

◆ Schedule() [1/4]

template<typename _Rep , typename _Period >
TaskContext & TaskContext::Schedule ( std::chrono::duration< _Rep, _Period > const &  time,
TaskScheduler::group_t const  group,
TaskScheduler::task_handler_t const &  task 
)
inline

Schedule an event with a fixed rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick.

617 {
618 return Dispatch([&](TaskScheduler& scheduler) -> TaskScheduler&
619 {
620 return scheduler.ScheduleAt(_task->_end, TaskScheduler::MakeDurationCalculator(time), group, task);
621 });
622 }
The TaskScheduler class provides the ability to schedule std::function's in the near future....
Definition: TaskScheduler.hpp:58
TaskScheduler & ScheduleAt(timepoint_t const &end, duration_calculator_t &&duration_calculator, task_handler_t const &task)
Definition: TaskScheduler.hpp:410

References _task, Dispatch(), TaskScheduler::MakeDurationCalculator(), and TaskScheduler::ScheduleAt().

+ Here is the call graph for this function:

◆ Schedule() [2/4]

template<typename _Rep , typename _Period >
TaskContext & TaskContext::Schedule ( std::chrono::duration< _Rep, _Period > const &  time,
TaskScheduler::task_handler_t const &  task 
)
inline

Schedule an event with a fixed rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick.

603 {
604 return Dispatch([&](TaskScheduler& scheduler) -> TaskScheduler&
605 {
606 return scheduler.ScheduleAt(_task->_end, TaskScheduler::MakeDurationCalculator(time), task);
607 });
608 }

References _task, Dispatch(), TaskScheduler::MakeDurationCalculator(), and TaskScheduler::ScheduleAt().

+ Here is the call graph for this function:

◆ Schedule() [3/4]

template<typename _RepLeft , typename _PeriodLeft , typename _RepRight , typename _PeriodRight >
TaskContext & TaskContext::Schedule ( std::chrono::duration< _RepLeft, _PeriodLeft > const &  min,
std::chrono::duration< _RepRight, _PeriodRight > const &  max,
TaskScheduler::group_t const  group,
TaskScheduler::task_handler_t const &  task 
)
inline

Schedule an event with a randomized rate between min and max rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick.

646 {
647 return Dispatch([&](TaskScheduler& scheduler) -> TaskScheduler&
648 {
649 return scheduler.ScheduleAt(_task->_end, TaskScheduler::MakeDurationCalculator(min, max), group, task);
650 });
651 }

References _task, Dispatch(), TaskScheduler::MakeDurationCalculator(), and TaskScheduler::ScheduleAt().

+ Here is the call graph for this function:

◆ Schedule() [4/4]

template<typename _RepLeft , typename _PeriodLeft , typename _RepRight , typename _PeriodRight >
TaskContext & TaskContext::Schedule ( std::chrono::duration< _RepLeft, _PeriodLeft > const &  min,
std::chrono::duration< _RepRight, _PeriodRight > const &  max,
TaskScheduler::task_handler_t const &  task 
)
inline

Schedule an event with a randomized rate between min and max rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick.

631 {
632 return Dispatch([&](TaskScheduler& scheduler) -> TaskScheduler&
633 {
634 return scheduler.ScheduleAt(_task->_end, TaskScheduler::MakeDurationCalculator(min, max), task);
635 });
636 }

References _task, Dispatch(), TaskScheduler::MakeDurationCalculator(), and TaskScheduler::ScheduleAt().

+ Here is the call graph for this function:

◆ SetGroup()

TaskContext & TaskContext::SetGroup ( TaskScheduler::group_t const  group)

Sets the event in the given group.

201{
202 _task->_group = TaskScheduler::MakeUnique<TaskScheduler::group_t>(group);
203 return *this;
204}

◆ ThrowOnConsumed()

void TaskContext::ThrowOnConsumed ( ) const
private

Throws std::logic_error if the task was consumed already.

238{
239 // Catch multiple rescheduling caused through bad logic.
240 if (*_consumed)
241 throw std::logic_error("Bad task logic, task context was consumed already!");
242}

Referenced by Repeat().

+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ TaskScheduler

friend class TaskScheduler
friend

Member Data Documentation

◆ _consumed

std::shared_ptr<bool> TaskContext::_consumed
private

Marks the task as consumed.

Referenced by operator=().

◆ _owner

std::weak_ptr<TaskScheduler> TaskContext::_owner
private

Owner.

Referenced by operator=().

◆ _task

TaskScheduler::TaskContainer TaskContext::_task
private

Associated task.

Referenced by operator=(), Repeat(), RescheduleAll(), RescheduleGroup(), and Schedule().


The documentation for this class was generated from the following files: