alibaba / alibaba/yalantinglibs

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

Open
#307 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
2.2k
Forks
327
Avg merge
1d 20h
Merged PRs (30d)
2

Description

### Search before asking

- [x] I searched the [issues](https://github.com/alibaba/yalantinglibs/issues) and found no similar issues.

### What happened + What you expected to happen

https://github.com/alibaba/yalantinglibs/blob/c75fdff50b43a153b9f86a50cafea060487e21e7/src/coro_rpc/examples/helloworld/server/main.cpp#L22-L38

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()`.

```.cpp

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!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with src/coro_rpc/examples/helloworld/server/main.cpp, especially the service construction before server.start(), then trace register_handler and the service dispatch path. Determine how a creation callback could be accepted and invoked only when the registered service is called. Done means services can be registered without pre-constructing their objects and are created on demand.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.