class AsyncTaskTree

Defined at line 48 of file ../../src/developer/debug/zxdb/client/async_task_tree.h

Represents a logical tree of async tasks, possibly associated with an executor.

This object is like the "stack" of asynchronous tasks that are registered with some asynchronous

runtime (from here on, just "the runtime").

Unlike the Stack, which is allocated by the operating system at thread creation time, and has a

single list of stack frames, asynchronous runtimes are opted in by particular programs if they so

choose, which can operate in single or multithreaded environments, and coordinate trees of

asynchronous tasks. The tasks may be in many states, such as waiting on I/O operations,

suspended, completed, or any other of many states that are defined by a particular runtime. These

asynchronous tasks will always have some memory associated with them to hold the current state

(e.g. "stackless" coroutines), or they may contain a small "stack" region within themselves to

perform allocations (e.g. "stackful" coroutines).

Our goal is to abstract away as many of these details as possible from different runtimes and

languages to present a common interface for interacting with these objects for inspection and

traversal, just like stack frames are today.

The interface for this class is the entrypoint for interacting with the runtime and all of the

currently live task objects that are registered with the runtime.

The suppliers are responsible for providing the Delegate interface to construct new task objects

and inject them into the tree.

The consumers may use the getters or provided iteration methods to perform operations against the

tasks present in the tree.

Public Methods

void AsyncTaskTree (Delegate * delegate)

Defined at line 11 of file ../../src/developer/debug/zxdb/client/async_task_tree.cc

void ~AsyncTaskTree ()

Defined at line 13 of file ../../src/developer/debug/zxdb/client/async_task_tree.cc

fxl::WeakPtr<AsyncTaskTree> GetWeakPtr ()

Defined at line 15 of file ../../src/developer/debug/zxdb/client/async_task_tree.cc

void Sync (Thread * thread, fit::callback<void (const Err &, const Frame *const)> callback)

Requests that all task information be updated. Automatically requests the full stack if it

isn't already present.

Defined at line 17 of file ../../src/developer/debug/zxdb/client/async_task_tree.cc

void SetTasks (std::vector<std::unique_ptr<AsyncTask>> tasks)

Provides a new set of root tasks.

Defined at line 56 of file ../../src/developer/debug/zxdb/client/async_task_tree.cc

void ClearTasks ()

Removes all tasks.

Defined at line 69 of file ../../src/developer/debug/zxdb/client/async_task_tree.cc

void ForEach (fit::function<void (const TaskEntry &)> fn)

Performs a depth-first iteration of all tasks in the tree, calling |fn| on each entry.

Defined at line 34 of file ../../src/developer/debug/zxdb/client/async_task_tree.cc

bool has_tasks ()

Returns whether or not the task tree is non-empty. If this method returns true it means the

traversal methods below will work without calling |Sync| first. This is primarily an

optimization for callers to use to avoid calling |Sync| repeatedly on a task tree that has

already been cached.

Defined at line 72 of file ../../src/developer/debug/zxdb/client/async_task_tree.h

template <typename Node, typename PopulateFn, typename ChildrenFn>
std::vector<Node> Map (PopulateFn populate_fn, ChildrenFn children_fn)

Transforms the tree of AsyncTasks into a tree of arbitrary Node types.

This method uses an iterative, stack-based approach to traverse the tree,

avoiding potential stack overflow issues that can occur with recursive

traversal of deeply nested task structures. Prefer using this or ForEach

when possible.

Parameters:

populate_fn: A callable with signature `void(const AsyncTask

&

task, Node*

node)`. It is responsible for copying data from the `task`

into the `node`.

children_fn: A callable with signature `std::vector

<Node

>*(Node* node)`.

It must return a pointer to a `std::vector` that holds the

children of the given `node`. This allows the Map function

to resize the container and push child nodes onto its

processing stack.

Example:

```cpp

struct MyNode {

std::string name;

std::vector

<MyNode

> children;

};

std::vector

<MyNode

> result = tree.Map

<MyNode

>(

[](const zxdb::AsyncTask

&

task, MyNode* node) {

node->name = task.GetIdentifier().GetFullName();

},

[](MyNode* node) {

return

&node

->children;

});

```

Defined at line 130 of file ../../src/developer/debug/zxdb/client/async_task_tree.h

Records