组类
class Tasking::GroupGroup 表示描述如何执行和处理嵌套异步任务树的基本元素。更多信息...
头文件 | #include <solutions/tasking/tasktree.h> |
继承自 | Tasking::ExecutableItem |
注意: 此类中所有函数均可重入。
公共函数
Group(const QList<Tasking::GroupItem> &children) | |
Group(std::initializer_list<Tasking::GroupItem> children) |
详细描述
Group 是其他组元素的容器。它将子任务包含在一个单元中,对该组父元素来说被视为单个异步任务。由于 Group 是 GroupItem 类型,它也可以是 Group 的子元素。
使用别名的自定义任务名称将子任务插入组中,例如,ConcurrentCallTask<ResultType>
或 NetworkQueryTask
const Group group { NetworkQueryTask(...), ConcurrentCallTask<int>(...) };
通过插入 parallelLimit() 或 workflowPolicy() 函数返回的项目可以定制组的行为
const Group group { parallel, continueOnError, NetworkQueryTask(...), NetworkQueryTask(...) };
组可以包含嵌套组
const Group group { finishAllAndSuccess, NetworkQueryTask(...), Group { NetworkQueryTask(...), Group { parallel, NetworkQueryTask(...), NetworkQueryTask(...), } ConcurrentCallTask<QString>(...) } };
组可以动态实例化自定义存储结构,可用于任务间数据交换
struct MyCustomStruct { QByteArray data; }; Storage<MyCustomStruct> storage; const auto onFirstSetup = [](NetworkQuery &task) { ... }; const auto onFirstDone = [storage](const NetworkQuery &task) { // storage-> gives a pointer to MyCustomStruct instance, // created dynamically by the running task tree. storage->data = task.reply()->readAll(); }; const auto onSecondSetup = [storage](ConcurrentCall<QImage> &task) { // storage-> gives a pointer to MyCustomStruct. Since the group is sequential, // the stored MyCustomStruct was already updated inside the onFirstDone handler. const QByteArray storedData = storage->data; }; const Group group { // When the group is entered by a running task tree, it creates MyCustomStruct // instance dynamically. It is later accessible from all handlers via // the *storage or storage-> operators. sequential, storage, NetworkQueryTask(onFirstSetup, onFirstDone, CallDoneIf::Success), ConcurrentCallTask<QImage>(onSecondSetup) };
成员函数文档
Group::Group(const QList<Tasking::GroupItem> &children)
根据给定的 children 列表构造一个组。
此构造函数在组的子元素在编译时未知,但在运行时知道时很有用
const QStringList sourceList = ...; QList<GroupItem> groupItems { parallel }; for (const QString &source : sourceList) { const NetworkQueryTask task(...); // use source for setup handler groupItems << task; } const Group group(groupItems);
Group::Group(std::initializer_list<Tasking::GroupItem> children)
从 children 给定的 std::initializer_list
构造一个组。
此构造函数在组的所有子项在编译时都知道时很有用
const Group group { finishAllAndSuccess, NetworkQueryTask(...), Group { NetworkQueryTask(...), Group { parallel, NetworkQueryTask(...), NetworkQueryTask(...), } ConcurrentCallTask<QString>(...) } };
©2024 The Qt Company Ltd. 包含在本文档中的文档贡献属于其各自所有者的版权。本提供的文档根据 Free Software Foundation 发布的 GNU 自由文档许可协议版本 1.3 的条款进行许可。Qt 和相应标志是 The Qt Company Ltd 在芬兰及/或其他国家和地区的商标。所有其他商标均为各自所有者的财产。