Skip to content

Latest commit

 

History

History
31 lines (24 loc) · 1.13 KB

README.md

File metadata and controls

31 lines (24 loc) · 1.13 KB

test application for grpc4p library. gRPC with an API like the javascript Promises.

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  promise  =  asyncGrpc.call(&helloworld::Greeter::Stub::PrepareAsyncSayHello)(_req,call);

promise->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  <<  e.what() <<  '\n';
    }
}).error([](){
    std::cerr  <<  "call failed! \n";
});