You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by GitBox <gi...@apache.org> on 2020/09/16 07:13:05 UTC

[GitHub] [incubator-brpc] feng-y edited a comment on issue #1243: brpc::Join(CallId id) 支持带超时的等待

feng-y edited a comment on issue #1243:
URL: https://github.com/apache/incubator-brpc/issues/1243#issuecomment-693219844


   一个不太靠谱的基于future的实现
   ```
   void HandleEchoResponse(
           brpc::Controller* cntl,
           example::EchoResponse* response,
           std::shared_ptr<std::promise<bool>> waiter) {
       waiter->set_value(true);
   }
         std::shared_ptr<std::promise<bool>> waiter(std::make_shared<std::promise<bool>>());
   
           // Because `done'(last parameter) is NULL, this function waits until
           // the response comes back or error occurs(including timedout).
           google::protobuf::Closure* done = brpc::NewCallback(
               &HandleEchoResponse, &cntl, &response, waiter);
   
           auto call_id = cntl.call_id();
           stub.Echo(&cntl, &request, &response, done);
           LOG(INFO) << "waiting Join:" << errno << ", " << EINVAL;
           // brpc::Join(call_id);
           if (waiter->get_future().wait_for(std::chrono::microseconds(1)) != std::future_status::ready) {
             LOG(INFO) << "timeout";
             brpc::StartCancel(call_id);
           } else {
           .......
          }
   
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org