Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[coro_rpc] Create the object of service on-demand may be supported #307

Open
1 of 2 tasks
yanminhui opened this issue Jun 4, 2023 · 1 comment
Open
1 of 2 tasks
Labels
enhancement New feature or request

Comments

@yanminhui
Copy link

Search before asking

  • I searched the issues and found no similar issues.

What happened + What you expected to happen

int main() {
// start rpc server
coro_rpc_server server(std::thread::hardware_concurrency(), 8801);
// regist normal function for rpc
server.register_handler<hello_world, A_add_B, hello_with_delay, echo,
coro_echo>();
// regist member function for rpc
HelloService hello_service;
server
.register_handler<&HelloService::hello, &HelloService::hello_with_delay>(
&hello_service);
// start server
return server.start() == std::errc{};
}

Now, create the object of service (e.g. hello_service) before server.start() as pre-condition, but create the object of service is not necessary if service is not called.

It can be supported that allow user creates the object of service while the service is called.

for example, pass one function create() to register_handler().

HelloService* create() 
{
    static HelloService hello_service;
    return &hello_service;
} 

server.register_handler<&HelloService::hello>(create);

Reproduction way

Anything else

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!
@poor-circle
Copy link
Collaborator

Lazy evalutation is a good idea, would you like submit a PR? Or I will support this.

@poor-circle poor-circle added the enhancement New feature or request label Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants