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

Method run

example/E03-ThirdFlow.cpp:53–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51class ProcessGNode : public GNode {
52public:
53 CStatus run() override {
54 while (true) {
55 std::shared_ptr<InputMParam> input = nullptr;
56 auto status = CGRAPH_RECV_MPARAM_WITH_TIMEOUT(InputMParam, INPUT_TOPIC_NAME, input, 1000);
57 if (status.isErr()) {
58 break; // 一阵子收不到消息了,就自动停止好了
59 }
60
61 int ms = randomSleep(1, 100); // 模拟处理流程,随机休息不超过 100ms
62 std::shared_ptr<ResultMParam> result(new ResultMParam);
63 switch (input->num_) {
64 case 1: result->eng_info_ = "one"; break;
65 case 2: result->eng_info_ = "two"; break;
66 case 3: result->eng_info_ = "three"; break;
67 default: result->eng_info_ = "other";
68 }
69 result->negative_num_ = -1 * input->num_;
70 result->process_ts_ = ms;
71
72 CGRAPH_SEND_MPARAM(ResultMParam, RESULT_TOPIC_NAME, result, GMessagePushStrategy::WAIT);
73 }
74
75 CGRAPH_ECHO(" ----> ProcessGNode run finished");
76 return CStatus();
77 }
78};
79
80

Callers

nothing calls this directly

Calls 3

randomSleepFunction · 0.85
CGRAPH_ECHOFunction · 0.85
isErrMethod · 0.80

Tested by

no test coverage detected