feng-y edited a comment on issue #1243:
URL: https://github.com/apache/incubator-brpc/issues/1243#issuecomment-693219844
一个不太靠谱的基于future的实现
callback 里面设置 future
```
void HandleEchoResponse(
brpc::Controller* cntl,
example::EchoResponse* response,
std::shared_ptr<std::promise<bool>> waiter) {
waiter->set_value(true);
}
```
等待的时候不join, 等future ,如果futre 不成功就 cancel 请求
```
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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]