21using namespace std::chrono_literals;
23TEST(rpc, compilation_tests) {
27 server.
BindSync(
"bind00", []() {
return 2.0f; });
29 server.
BindSync(
"bind01", [](
int x) {
return x; });
31 server.
BindSync(
"bind02", [](
int,
float) {
return 0.0; });
33 server.
BindSync(
"bind03", [](
int,
float,
double,
char) {});
36TEST(rpc, server_bind_sync_run_on_game_thread) {
38 const auto main_thread_id = std::this_thread::get_id();
44 server.
BindSync(
"do_the_thing", [=](
int x,
int y) ->
int {
45 EXPECT_EQ(std::this_thread::get_id(), main_thread_id);
51 std::atomic_bool done{
false};
59 for (
auto i = 0; i < 300; ++i) {
61 auto result =
client.call(
"do_the_thing", i, 1).as<
int>();
62 EXPECT_EQ(result, i + 1);
70 for (; i < 1'000'000u; ++i) {
79 std::cout <<
"game thread: run " << i <<
" slices.\n";
void CreateThread(F &&functor)
一个RPC服务器,可以将功能绑定为同步或异步运行。
void SyncRunFor(time_duration duration)
void AsyncRun(size_t worker_threads)
void BindSync(const std::string &name, FunctorT &&functor)
constexpr uint16_t TESTING_PORT
TEST(rpc, compilation_tests)