feat(build): add constructor from_arc
for gRPC servers
#875
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ownArc<Service>
, making the second layer ofArc<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 usingArc
if that should ever be desired.