class AsyncTaskManager

A class to manage a loose queue of isolated tasks, which can be performed either synchronously (in the foreground thread) or asynchronously (by a background thread).

The AsyncTaskManager is actually a collection of AsyncTaskChains, each of which maintains a list of tasks. Each chain can be either foreground or background (it may run only in the main thread, or it may be serviced by one or more background threads). See AsyncTaskChain for more information.

If you do not require background processing, it is perfectly acceptable to create only one AsyncTaskChain, which runs in the main thread. This is a common configuration.

Inheritance diagram

__init__(name: str) → None
property active_tasks

Returns the set of tasks that are active (and not sleeping) on the task manager, at the time of the call.

Return type

add(task: AsyncTask) → None

cleanup() → None

Stops all threads and messily empties the task list. This is intended to be called on destruction only.

property clock
Getter

Returns the clock pointer used within the AsyncTaskManager. See setClock().

Setter

Replaces the clock pointer used within the AsyncTaskManager. This is used to control when tasks with a set_delay() specified will be scheduled. It can also be ticked automatically each epoch, if set_tick_clock() is true.

The default is the global clock pointer.

Return type

ClockObject

findTask(name: str) → AsyncTask

Returns the first task found with the indicated name, or NULL if there is no task with the indicated name.

If there are multiple tasks with the same name, returns one of them arbitrarily.

Return type

findTaskChain(name: str) → AsyncTaskChain

Searches a new AsyncTaskChain of the indicated name and returns it if it exists, or NULL otherwise.

Return type

findTasks(name: str) → AsyncTaskCollection

Returns the list of tasks found with the indicated name.

Return type

findTasksMatching(pattern: GlobPattern) → AsyncTaskCollection

Returns the list of tasks found whose name matches the indicated glob pattern, e.g. “my_task_*”.

Return type

getActiveTasks() → AsyncTaskCollection

Returns the set of tasks that are active (and not sleeping) on the task manager, at the time of the call.

Return type

static getClassType() → TypeHandle
Return type

TypeHandle

getClock() → ClockObject

Returns the clock pointer used within the AsyncTaskManager. See setClock().

Return type

ClockObject

static getGlobalPtr() → AsyncTaskManager

Returns a pointer to the global AsyncTaskManager. This is the AsyncTaskManager that most code should use for queueing tasks and suchlike.

Return type

getNextWakeTime() → float

Returns the scheduled time (on the manager’s clock) of the next sleeping task, on any task chain, to awaken. Returns -1 if there are no sleeping tasks.

getNumTaskChains() → int

Returns the number of different task chains.

getNumTasks() → size_t

Returns the number of tasks that are currently active or sleeping within the task manager.

Return type

size_t

getSleepingTasks() → AsyncTaskCollection

Returns the set of tasks that are sleeping (and not active) on the task manager, at the time of the call.

Return type

getTaskChain(n: int) → AsyncTaskChain

Return type

getTaskChains() → list
getTasks() → AsyncTaskCollection

Returns the set of tasks that are active or sleeping on the task manager, at the time of the call.

Return type

hasTask(task: AsyncTask) → bool

Returns true if the indicated task has been added to this AsyncTaskManager, false otherwise.

makeTaskChain(name: str) → AsyncTaskChain

Creates a new AsyncTaskChain of the indicated name and stores it within the AsyncTaskManager. If a task chain with this name already exists, returns it instead.

Return type

property next_wake_time

Returns the scheduled time (on the manager’s clock) of the next sleeping task, on any task chain, to awaken. Returns -1 if there are no sleeping tasks.

Return type

float

output(out: ostream) → None
poll() → None

Runs through all the tasks in the task list, once, if the task manager is running in single-threaded mode (no threads available). This method does nothing in threaded mode, so it may safely be called in either case.

remove(task: AsyncTask) → bool

Removes the indicated task from the active queue. Returns true if the task is successfully removed, or false if it wasn’t there.

remove(tasks: AsyncTaskCollection) → size_t

Removes all of the tasks in the AsyncTaskCollection. Returns the number of tasks removed.

Return type

size_t

removeTaskChain(name: str) → bool

Removes the AsyncTaskChain of the indicated name. If the chain still has tasks, this will block until all tasks are finished.

Returns true if successful, or false if the chain did not exist.

setClock(clock: ClockObject) → None

Replaces the clock pointer used within the AsyncTaskManager. This is used to control when tasks with a set_delay() specified will be scheduled. It can also be ticked automatically each epoch, if set_tick_clock() is true.

The default is the global clock pointer.

property sleeping_tasks

Returns the set of tasks that are sleeping (and not active) on the task manager, at the time of the call.

Return type

startThreads() → None

stopThreads() → None

Stops any threads that are currently running. If any tasks are still pending and have not yet been picked up by a thread, they will not be serviced unless poll() or startThreads() is later called.

property tasks

Returns the set of tasks that are active or sleeping on the task manager, at the time of the call.

Return type

waitForTasks() → None
write(out: ostream, indent_level: int) → None