29 _now = clock_t::now();
36 return Update(std::chrono::milliseconds(milliseconds), callback);
57 return task->IsInGroup(group);
123 container.erase(container.begin());
129 return *container.begin();
139 for (
auto itr = container.begin(); itr != container.end();)
141 itr = container.erase(itr);
148 std::vector<TaskContainer> cache;
149 for (
auto itr = container.begin(); itr != container.end();)
152 cache.push_back(*itr);
153 itr = container.erase(itr);
158 container.insert(cache.begin(), cache.end());
163 return container.empty();
168 if (std::shared_ptr<TaskScheduler> owner = _owner.lock())
176 return _owner.expired();
181 return _task->IsInGroup(group);
186 _task->_group = group;
192 _task->_group = std::nullopt;
198 return _task->_repeated;
205 return scheduler.
Async(callable);
234 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 & CancelGroup(group_t group)
TaskScheduler & CancelAll()
std::shared_ptr< Task > TaskContainer
TaskScheduler & CancelGroupsOf(std::vector< group_t > const &groups)
void Dispatch(success_t const &callback)
Dispatch remaining tasks.
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 & 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
TaskScheduler & Async(std::function< void()> callable)
TaskScheduler & Update(success_t const &callback=nullptr)
static bool EmptyValidator()
TaskQueue _task_holder
The Task Queue which contains all task objects.