mirror of
https://github.com/qicosmos/rest_rpc.git
synced 2026-08-29 08:34:47 +08:00
Merge branch 'master' of https://github.com/qicosmos/rest_rpc
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
|
||||
using namespace rest_rpc::rpc_service;
|
||||
@@ -201,29 +202,6 @@ public:
|
||||
bool has_connected() const { return has_connected_; }
|
||||
|
||||
// sync call
|
||||
#if __cplusplus > 201402L
|
||||
template <size_t TIMEOUT, typename T = void, typename... Args>
|
||||
auto call(const std::string &rpc_name, Args &&...args) {
|
||||
std::future<req_result> future =
|
||||
async_call<FUTURE>(rpc_name, std::forward<Args>(args)...);
|
||||
auto status = future.wait_for(std::chrono::milliseconds(TIMEOUT));
|
||||
if (status == std::future_status::timeout ||
|
||||
status == std::future_status::deferred) {
|
||||
throw std::out_of_range("timeout or deferred");
|
||||
}
|
||||
|
||||
if constexpr (std::is_void_v<T>) {
|
||||
future.get().as();
|
||||
} else {
|
||||
return future.get().template as<T>();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T = void, typename... Args>
|
||||
auto call(const std::string &rpc_name, Args &&...args) {
|
||||
return call<DEFAULT_TIMEOUT, T>(rpc_name, std::forward<Args>(args)...);
|
||||
}
|
||||
#else
|
||||
template <size_t TIMEOUT, typename T = void, typename... Args>
|
||||
typename std::enable_if<std::is_void<T>::value>::type
|
||||
call(const std::string &rpc_name, Args &&...args) {
|
||||
@@ -271,7 +249,6 @@ public:
|
||||
call(const std::string &rpc_name, Args &&...args) {
|
||||
return call<DEFAULT_TIMEOUT, T>(rpc_name, std::forward<Args>(args)...);
|
||||
}
|
||||
#endif
|
||||
|
||||
template <CallModel model, typename... Args>
|
||||
future_result<req_result> async_call(const std::string &rpc_name,
|
||||
@@ -629,7 +606,7 @@ private:
|
||||
auto &f = future_map_[req_id];
|
||||
if (ec) {
|
||||
// LOG<<ec.message();
|
||||
if (!f) {
|
||||
if (f) {
|
||||
// std::cout << "invalid req_id" << std::endl;
|
||||
f->set_value(req_result{""});
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user