Preliminary. ThinkMeta ConcurrentTasks and this documentation are preliminary; everything is subject to change.

API reference / Tasks

Task class

The library's base class for tasks.

Use
import ThinkMeta.ConcurrentTasks.Tasks.Task;
Namespace
ThinkMeta::ConcurrentTasks::Tasks
Inherits
ITask

Syntax

class Task : public ITask

Remarks

Derive from it and implement ITask::Run. It can be started at once or by time, and tells an optional INotifyTaskStateChange when it has exited. The object is owned by the caller and must outlive the task: from Schedule until OnTaskExited has been called (e.g. wait for it with a WaitableTask or a Synchronization::TaskGroup).

See also

LambdaTask

Constructors

Taskprotected

Constructs the task.

Syntax

explicit Task(INotifyTaskStateChange* notifyTaskStateChange = nullptr) noexcept;

Parameters

notifyTaskStateChangeINotifyTaskStateChange*
Told when the task exits; may be nullptr.Default: nullptr

Methods

OnTaskExited

Called by the core when the task has exited.

Syntax

void OnTaskExited() noexcept override;

Remarks

Tells the notify callback, if any. From then on the notified party may destroy or reuse the task object.

See also

SetNotifyCallback

SetNotifyCallback

Sets the object OnTaskExited forwards to.

Syntax

void SetNotifyCallback(
    INotifyTaskStateChange* notifyTaskStateChange
) noexcept override;

Parameters

notifyTaskStateChangeINotifyTaskStateChange*
The observer, borrowed: it must stay valid until the task has exited. nullptr: none.

Remarks

Replaces the one given to the constructor (Synchronization::TaskGroup uses it to count its tasks). Set it before the task is scheduled.

GetTimerData

Returns the task's own timer storage.

Syntax

TaskTimerData* GetTimerData() noexcept override;

Return value

Type: TaskTimerData*

Storage inside this object; never nullptr.

Remarks

So Task objects can be started by time.

Schedule

Adds the task to the calling task's scheduler.

Syntax

void Schedule(TaskPriority taskPriority = TaskPriority::Default) noexcept;

Parameters

taskPriorityTaskPriority
Priority the task runs with; TaskPriority::Default inherits the calling task's priority.Default: TaskPriority::Default

Remarks

Uses ITaskScheduler::AddTask. Call it from a task running on a scheduler; from a plain or converted thread call AddTask on the scheduler object instead.

See also

CancelSchedule

Adds the task to the calling task's scheduler after a delay.

Syntax

bool Schedule(TaskPriority taskPriority, Duration delay) noexcept;

Parameters

taskPriorityTaskPriority
Priority the task runs with; TaskPriority::Default inherits the calling task's priority.
delayDuration
Time from now until the task is queued, as a Duration (e.g. Duration::Milliseconds).

Return value

Type: bool

true if the task is waiting to start; false if the task cannot be started by time (see ITaskScheduler::AddTimedTask).

Remarks

Needs EnableTimers. Called again before the task has started, it moves the start. On false the task was not added: it neither runs nor exits, so OnTaskExited is not called. Usage rule: a task already counted into a Synchronization::TaskGroup stays counted and the group's Wait never returns, unless you start it without delay (Schedule with the priority only) or report its exit yourself by calling its OnTaskExited, which counts it out of the group.

See also

CancelSchedule, ScheduleNow

CancelSchedule

Takes back a start by time that has not happened yet.

Syntax

bool CancelSchedule() noexcept;

Return value

Type: bool

true if the start was taken back; false if the task had started already or was not started by time.

Remarks

The task exits without running (OnTaskExited). Never blocks.

See also

CancelTimedTask

ScheduleNow

Starts a task scheduled by time now instead of later.

Syntax

bool ScheduleNow() noexcept;

Return value

Type: bool

true if the task was queued now; false if it was not waiting to start.

Remarks

For a task started by Schedule with a delay.

See also

ScheduleTimedTask

SleepFor

Lets the calling task sleep.

Syntax

static bool SleepFor(Duration duration) noexcept;

Parameters

durationDuration
Minimum time to sleep, as a Duration (e.g. Duration::Milliseconds).

Return value

Type: bool

true after the sleep; false at once without EnableTimers.

Remarks

The thread runs other tasks meanwhile.

See also

SleepTask

Create

Returns a LambdaTask that runs a callable.

Syntax

template <std::invocable F>
static auto Create(
    F&& func,
    INotifyTaskStateChange* notifyTaskStateChange = nullptr
) noexcept;

Template parameters

Fstd::invocable
Type of the callable: invocable without arguments; it must not throw.

Parameters

funcF&&
The callable; stored by value (copied or moved).
notifyTaskStateChangeINotifyTaskStateChange*
Told when the task exits; borrowed, must stay valid until then. May be nullptr.Default: nullptr

Return value

Type: auto

The unscheduled task, a LambdaTask of the decayed callable type.

Remarks

The task is returned by value and is not scheduled yet: keep it in a variable that outlives the task and call Schedule or ITaskScheduler::AddTask on it. References captured by func must stay valid until the task has exited.

GetNotifyCallbackprotected

Returns the object that is told when the task exits.

Syntax

INotifyTaskStateChange* GetNotifyCallback() const noexcept;

Return value

Type: INotifyTaskStateChange*

The notify callback, or nullptr if none is set.

Remarks

For an OnTaskExited override that must not touch the task any more after releasing its own waiters: read the callback first, then release, then notify.

Generated from ThinkMeta.ConcurrentTasks.API @ 137ec1d (2026-10-17).