Skip to content

Don't require Client to be wrapped in Arc #71

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

Merged
merged 4 commits into from
Jul 26, 2024
Merged

Conversation

tclem
Copy link
Member

@tclem tclem commented Jul 25, 2024

I'd like the twirp::Client to behave a little closer to the underly reqwest::Client which doesn't require a wrapping Arc to reuse.

There is one tricky requirement here that we have over in blackbird - and that is that we dynamically set the hostname per request in one primary use case of this library. I'd previously implemented that as per-request middleware, but that was a bit tricky to get working with the inner Arc approach so I've opted for a less generic version of the same functionality.

Breaking change, so I've bumped the version.

@tclem tclem requested a review from a team as a code owner July 25, 2024 23:36
http_client,
middlewares,
inner: Arc::new(ClientRef {
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the only variable part is the host field...
Therefore, it makes sense IMO to move the http_client also into the ClientRef struct so that all the immutable parts are shared with just one Arc.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since http_client is a reqwest::Client it's already internally managing another Arc so I don't know if it makes sense to add one more layer of Arcs.

@tclem tclem added this pull request to the merge queue Jul 26, 2024
Merged via the queue into main with commit 5c94229 Jul 26, 2024
2 checks passed
@tclem tclem deleted the tclem/cheap-cloning branch July 26, 2024 15:56
@CleanCut
Copy link
Contributor

This PR was included in v0.8.0, released today.

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.

3 participants