diff --git a/examples/client/main.cpp b/examples/client/main.cpp index 315dac3..ca03b83 100644 --- a/examples/client/main.cpp +++ b/examples/client/main.cpp @@ -3,7 +3,6 @@ #include #include #include "codec.h" -using namespace std::chrono_literals; using namespace rest_rpc; using namespace rest_rpc::rpc_service; @@ -114,7 +113,7 @@ void test_async_client() { }); auto f = client.async_call("get_person"); - if (f.wait_for(50ms) == std::future_status::timeout) { + if (f.wait_for(std::chrono::milliseconds(50)) == std::future_status::timeout) { std::cout << "timeout" << std::endl; } else { @@ -153,7 +152,7 @@ void test_upload() { { auto f = client.async_call("upload", "test", conent); - if (f.wait_for(500ms) == std::future_status::timeout) { + if (f.wait_for(std::chrono::milliseconds(500)) == std::future_status::timeout) { std::cout << "timeout" << std::endl; } else { @@ -163,7 +162,7 @@ void test_upload() { } { auto f = client.async_call("upload", "test1", conent); - if (f.wait_for(500ms) == std::future_status::timeout) { + if (f.wait_for(std::chrono::milliseconds(500)) == std::future_status::timeout) { std::cout << "timeout" << std::endl; } else { @@ -183,7 +182,7 @@ void test_download() { } auto f = client.async_call("download", "test"); - if (f.wait_for(500ms) == std::future_status::timeout) { + if (f.wait_for(std::chrono::milliseconds(500)) == std::future_status::timeout) { std::cout << "timeout" << std::endl; } else { @@ -214,7 +213,7 @@ void test_performance1() { for (size_t i = 0; i < 100000000; i++) { auto future = client.async_call("get_name", p); - auto status = future.wait_for(2s); + auto status = future.wait_for(std::chrono::seconds(2)); if (status == std::future_status::deferred) { std::cout << "deferred\n"; } diff --git a/include/rpc_client.hpp b/include/rpc_client.hpp index bd89bbf..8bf92bd 100644 --- a/include/rpc_client.hpp +++ b/include/rpc_client.hpp @@ -151,7 +151,7 @@ namespace rest_rpc { #endif template - auto async_call(const std::string& rpc_name, Args&&... args) { + std::future async_call(const std::string& rpc_name, Args&&... args) { req_id_++; auto future = get_future(); msgpack_codec codec; @@ -285,9 +285,15 @@ namespace rest_rpc { auto p = std::make_shared>(); std::future future = p->get_future(); - strand_.post([this, p1 = std::move(p)] () mutable { - future_map_.emplace(req_id_, std::move(p1)); +#if __cplusplus == 201103L + strand_.post([this, p]() mutable { + future_map_.emplace(req_id_, std::move(p)); }); +#else + strand_.post([this, p = std::move(p)]() mutable { + future_map_.emplace(req_id_, std::move(p)); + }); +#endif return future; }