29 _now = clock_t::now();
36 return Update(std::chrono::milliseconds(milliseconds), callback);
57 return task->IsInGroup(group);
64 std::for_each(groups.begin(), groups.end(),
122 container.erase(container.begin());
128 return *container.begin();
138 for (
auto itr = container.begin(); itr != container.end();)
140 itr = container.erase(itr);
147 std::vector<TaskContainer> cache;
148 for (
auto itr = container.begin(); itr != container.end();)
151 cache.push_back(*itr);
152 itr = container.erase(itr);
157 container.insert(cache.begin(), cache.end());
162 return container.empty();
167 if (
auto const owner = _owner.lock())
175 return _owner.expired();
180 return _task->IsInGroup(group);
185 _task->_group = group;
191 _task->_group = std::nullopt;
197 return _task->_repeated;
224 ASSERT(!(*_consumed) &&
"Bad task logic, task context was consumed already!");
void AssertOnConsumed() const
Asserts if the task was consumed already.
void Invoke()
Invokes the associated hook of the task.
TaskContext & Dispatch(std::function< TaskScheduler &(TaskScheduler &)> const &apply)
Dispatches an action safe on the TaskScheduler.
TaskContext & CancelAll()
Cancels all tasks from within the context.
TaskContext & SetGroup(TaskScheduler::group_t const group)
Sets the event in the given group.
TaskContext & Async(std::function< void()> const &callable)
TaskContext & CancelGroup(TaskScheduler::group_t const group)
Cancel all tasks of a single group from within the context.
TaskScheduler::repeated_t GetRepeatCounter() const
Returns the repeat counter which increases every time the task is repeated.
TaskContext & CancelGroupsOf(std::vector< TaskScheduler::group_t > const &groups)
TaskContext & ClearGroup()
Removes the group from the event.
bool IsInGroup(TaskScheduler::group_t const group) const
Returns true if the event is in the given group.
bool IsExpired() const
Returns true if the owner was deallocated and this context has expired.
void ModifyIf(std::function< bool(TaskContainer const &)> const &filter)
TaskContainer Pop()
Pops the task out of the container.
void RemoveIf(std::function< bool(TaskContainer const &)> const &filter)
TaskContainer const & First() const
std::multiset< TaskContainer, Compare > container
void Push(TaskContainer &&task)
TaskScheduler & CancelAll()
std::shared_ptr< Task > TaskContainer
TaskScheduler & Async(std::function< void()> const &callable)
TaskScheduler & CancelGroupsOf(std::vector< group_t > const &groups)
void Dispatch(success_t const &callback)
Dispatch remaining tasks.
TaskScheduler & Update(success_t const &callback=EmptyCallback)
std::function< void()> success_t
std::shared_ptr< TaskScheduler > self_reference
Contains a self reference to track if this object was deleted or not.
TaskScheduler & CancelGroup(group_t const group)
TaskScheduler & InsertTask(TaskContainer task)
Insert a new task to the enqueued tasks.
TaskScheduler & ClearValidator()
Clears the validator which is asked if tasks are allowed to be executed.
timepoint_t _now
The current time point (now)
std::queue< std::function< void()> > AsyncHolder
static bool EmptyValidator()
TaskQueue _task_holder
The Task Queue which contains all task objects.