MCPcopy Create free account
hub / github.com/ChunelFeng/CGraph / tutorial_cancel

Function tutorial_cancel

tutorial/T19-Cancel.cpp:14–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12using namespace CGraph;
13
14void tutorial_cancel() {
15 GPipelinePtr pipeline = GPipelineFactory::create();
16 GElementPtr a, b, c, d = nullptr;
17
18 CStatus status = pipeline->registerGElement<MyNode1>(&a, {}, "nodeA");
19 status += pipeline->registerGElement<MyNode1>(&b, {a}, "nodeB");
20 status += pipeline->registerGElement<MyNode1>(&c, {b}, "nodeC");
21 status += pipeline->registerGElement<MyNode2>(&d, {c}, "nodeD");
22 if (!status.isOK()) {
23 return; // 使用时,请对所有CGraph接口的返回值做判定。今后tutorial例子中省略该操作。
24 }
25
26 pipeline->init();
27
28 // 异步执行,并且等待结束
29 auto result = pipeline->asyncRun();
30 CGRAPH_ECHO("pipeline async run first time, BEGIN.");
31 result.wait();
32 CGRAPH_ECHO("pipeline async run first time, FINISH.");
33 CGRAPH_ECHO("======================");
34
35 result = pipeline->asyncRun();
36 CGRAPH_ECHO("pipeline async run second time, BEGIN.");
37 CGRAPH_SLEEP_MILLISECOND(1500)
38
39 /**
40 * pipeline整体流程,正常执行需要4000ms
41 * 等1500ms之后,手动cancel一下
42 */
43 pipeline->cancel();
44 CGRAPH_ECHO("pipeline async run second time, CANCEL.");
45 CGRAPH_ECHO("======================");
46
47 result.wait(); // 请务必等待执行完成之后,再进行destroy逻辑
48 pipeline->destroy();
49 GPipelineFactory::remove(pipeline);
50}
51
52
53int main () {

Callers 1

mainFunction · 0.70

Calls 9

createFunction · 0.85
CGRAPH_ECHOFunction · 0.85
removeFunction · 0.85
isOKMethod · 0.80
waitMethod · 0.80
cancelMethod · 0.80
initMethod · 0.45
asyncRunMethod · 0.45
destroyMethod · 0.45

Tested by

no test coverage detected