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

feat(build): add constructor from_arc for gRPC servers #875

Merged
merged 1 commit into from Jan 12, 2022
Merged

feat(build): add constructor from_arc for gRPC servers #875

merged 1 commit into from Jan 12, 2022

Conversation

athre0z
Copy link
Contributor

@athre0z athre0z commented Dec 30, 2021

Motivation

I found myself in a situation where I wanted to spawn a task on a timer in the background that interacts with the data in a gRPC service that I spawned. With the current code that is generated for servers, in order to do that, I'd have to add a second and unnecessary layer of Arc<Inner> to be able to access my data from both the spawned task and the gRPC service.

Solution

This PR adds a second constructor from_arc to the generated server, allowing the user to pass in their own Arc<Service>, making the second layer of Arc<T> unnecessary.

Possible drawbacks

The solution exposes the implementation detail of Arc being used internally to the user, making it harder to move away from using Arc if that should ever be desired.

Copy link
Member

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems very reasonable!

@LucioFranco LucioFranco changed the title codegen: add constructor from_arc for gRPC servers feat(build): add constructor from_arc for gRPC servers Jan 12, 2022
@LucioFranco LucioFranco merged commit 7179f7a into hyperium:master Jan 12, 2022
@athre0z athre0z deleted the add-server-from-arc branch January 12, 2022 22:03
djc pushed a commit to djc/tonic that referenced this pull request Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants