Merge branch 'master' of https://github.com/sogou/workflow into nossl

This commit is contained in:
Xie Han
2024-07-03 23:12:42 +08:00
3 changed files with 53 additions and 0 deletions

View File

@@ -84,6 +84,29 @@ Also, any of the following codes is legal and equivalent:
}
~~~
# Canceling successors
In graph tasks, we extend SeriesWork's **cancel** operation. When the series of a graph node is canceled, the operation will apply on all it's successive nodes recursively. The **cancel** operation is usually used in a task's callback:
~~~cpp
int main()
{
WFGraphTask *graph = WFTaskFactory::create_graph_task(graph_callback);
WFHttpTask *task = WFTaskFactory::create_http_task(url, 0, 0, [](WFHttpTask *t){
if (t->get_state() != WFT_STATE_SUCCESS)
series_of(t)->cancel();
});
WFGraphNode& a = graph->create_graph_node(task);
WFGraphNode& b = ...;
WFGraphNode& c = ...;
WFGraphNode& d = ...;
a-->b-->c;
b-->d;
graph->start();
...
}
~~~
In this case, when http task failed, nodes b, c, d will all be canceled, because the operation is recursive.
# Data passing
Because the tasks in a graph don't share a same series, there is no general method for passing data between graph nodes.

View File

@@ -85,6 +85,30 @@ WFGraphTask的create_graph_node接口产生一个图节点并返回节点的
接下来直接运行graph或者把graph放入任务流中就可以运行啦和一般的任务没有区别。
当然,把一个图任务变成另一个图的节点,也是完全正确的行为。
# 取消后继节点
在图任务里我们扩展了series的cancel操作这个操作会取消该节点的所有后继结点。
取消操作一般在节点任务的callback里执行例如
~~~cpp
int main()
{
WFGraphTask *graph = WFTaskFactory::create_graph_task(graph_callback);
WFHttpTask *task = WFTaskFactory::create_http_task(url, 0, 0, [](WFHttpTask *t){
if (t->get_state() != WFT_STATE_SUCCESS)
series_of(t)->cancel();
});
WFGraphNode& a = graph->create_graph_node(task);
WFGraphNode& b = ...;
WFGraphNode& c = ...;
WFGraphNode& d = ...;
a-->b-->c;
b-->d;
graph->start();
...
}
~~~
注意取消后继节点的操作是递归的这个例子里如果http任务失败b,c,d三个节点的任务都会被取消。
# 数据传递
图节点之间目前没有统一的数据传递方法它们并不共享某一个series。因此节点间数据传递需要用户解决。

View File

@@ -39,6 +39,12 @@ WFGraphNode::~WFGraphNode()
{
if (this->user_data)
{
if (series_of(this)->is_canceled())
{
for (WFGraphNode *node : this->successors)
series_of(node)->SeriesWork::cancel();
}
for (WFGraphNode *node : this->successors)
node->WFCounterTask::count();
}