voidtryGetRoom(Context& ctx){ // Asynchronously fetch the entire data-set, and convert it from json // to C++ objects was we go. // We expcet a list of Post objects cout << "getting room now!" << endl; list<Room> room_list; SerializeFromJson(room_list, ctx.Get(GetDockerUrl(roomListUrl)));
// Just dump the data. for (constauto& room: room_list) { RESTC_CPP_LOG_INFO_("Post id=" << room.id << ", title: " << room.name); } }
intmain(int argc, char *argv[]){
RESTC_CPP_TEST_LOGGING_SETUP("debug");
try {
auto rest_client = RestClient::Create(); cout << "trying to get rooms" << endl; // auto future = rest_client->ProcessWithPromise(DoSomethingInteresting); auto future = rest_client->ProcessWithPromise(tryGetRoom);
// Hold the main thread to allow the worker to do it's job future.get(); return0; } catch (const exception& ex) { RESTC_CPP_LOG_INFO_("main: Caught exception: " << ex.what()); }
return0; }
执行情况如下:
1 2 3 4 5 6 7 8 9 10 11
nash5@DESKTOP-0DDCG1U MINGW64 /f/prjs/restc-cpp/build/tests/functional/Release (master) $ ./basic_tests.exe trying to get rooms [2022-06-21 17:24:14.729043] [0x00008d94] [debug] Worker 0 is starting. getting room now! [2022-06-21 17:24:14.758042] [0x00008d94] [debug] Connecting to 114.55.47.169:443 [2022-06-21 17:24:14.807048] [0x00008d94] [debug] Sent GET request to 'https://mock.apifox.cn/m1/1153222-0-default/roomlist' {Connection f3f975c7-cbbb-44a4-8d0c-2c95450273e2 {TlsSocket socket# 624 192.168.5.44:50487 <--> 114.55.47.169:443}} [2022-06-21 17:24:14.888860] [0x00008d94] [info] Post id=1, title: room1 [2022-06-21 17:24:14.888860] [0x00008d94] [debug] Worker 0 is done.