Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
45 lines (33 loc) · 1.36 KB
/
Copy pathmain.cpp
File metadata and controls
45 lines (33 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <helloworld.grpc.pb.h>
#include <helloworld.pb.h>
#include <grpcPlusPromise/grpcPlusPromise.h>
#include <grpcPlusPromise/IAsyncCall.h>
#include <iostream>
#include <thread>
int main(int, char**) {
auto _channel_args = ::grpc::ChannelArguments();
auto shp_channel = ::grpc::CreateCustomChannel("127.0.0.1:50051", grpc::InsecureChannelCredentials(),
_channel_args);
GrcpPlusPromise<helloworld::Greeter> asyncGrpc(shp_channel);
std::thread thread(&GrcpPlusPromise<helloworld::Greeter>::AsyncCompleteRpc ,&asyncGrpc);
ASyncCall<AsyncCallData<helloworld::HelloReply>> *call = new ASyncCall<AsyncCallData<helloworld::HelloReply>>() ;
helloworld::HelloRequest _req;
auto ptr = asyncGrpc.call(&helloworld::Greeter::Stub::PrepareAsyncSayHello)(_req,call);
ptr->then([](std::any data){
std::cerr << "call success! \n";
}).then([](std::any data){
try
{
const auto _data = std::any_cast<ASyncCall<AsyncCallData<helloworld::HelloReply>> *>(data);
std::cerr << _data->_data.reply.message() << '\n';
}
catch (const std::bad_any_cast& e)
{
std::cerr << "call failed! \n";
std::cerr << e.what() << '\n';
}
}).error([](){
std::cerr << "call failed! \n";
});
thread.join();
}