| 1 |
/* |
| 2 |
* Copyright (C) 2024 KylinSoft Co., Ltd. |
| 3 |
* |
| 4 |
* This program is free software: you can redistribute it and/or modify it under |
| 5 |
* the terms of the GNU General Public License as published by the Free Software |
| 6 |
* Foundation, either version 3 of the License, or (at your option) any later |
| 7 |
* version. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 11 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU General Public License along with |
| 14 |
* this program. If not, see <https://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include <unistd.h> |
| 18 |
|
| 19 |
#include <thread> |
| 20 |
|
| 21 |
#include "scene.h" |
| 22 |
|
| 23 |
void workMethod3(const std::string &taskId) { |
| 24 |
PRINT_INFO("workMethod3 start, input: %s.\n", taskId.c_str()); |
| 25 |
sleep(10); |
| 26 |
Response output = Response::success(); |
| 27 |
output.add("p1", 11); |
| 28 |
output.add("p2", "hehe"); |
| 29 |
output.add("task", taskId); |
| 30 |
ASYNC_FLOW_RESPONSE_CONTINUE(taskId, output); |
| 31 |
PRINT_INFO("workMethod3 first call.\n"); |
| 32 |
|
| 33 |
output.clear(); |
| 34 |
sleep(10); |
| 35 |
output.add("p3", 22); |
| 36 |
output.add("p4", "hello"); |
| 37 |
output.add("task", taskId); |
| 38 |
ASYNC_FLOW_RESPONSE_CONTINUE(taskId, output); |
| 39 |
PRINT_INFO("workMethod3 second call.\n"); |
| 40 |
|
| 41 |
output = Response(ASYNC_FLOW_END); |
| 42 |
sleep(10); |
| 43 |
output.add("p5", 33); |
| 44 |
output.add("p6", "world"); |
| 45 |
output.add("task", taskId); |
| 46 |
ASYNC_FLOW_RESPONSE_END(taskId, output); |
| 47 |
PRINT_INFO("workMethod3 end.\n"); |
| 48 |
} |
| 49 |
|
| 50 |
Response handleAsyncFlowMethod(const std::string &taskId, const Request &request) { |
| 51 |
PRINT_DEBUG("method3 taskId: %s, request: %s\n", taskId.c_str(), request.toString().c_str()); |
| 52 |
|
| 53 |
// 异步处理 |
| 54 |
std::thread t(workMethod3, taskId); |
| 55 |
t.detach(); |
| 56 |
|
| 57 |
return Response::success(); |
| 58 |
} |
| 59 |
|
| 60 |
REGISTER_SERVICE_ASYNC_FLOW_HANDLER("asyncFlowMethod", handleAsyncFlowMethod) |