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

Add Pool::get_owned #107

Merged
merged 5 commits into from
Aug 11, 2021
Merged

Add Pool::get_owned #107

merged 5 commits into from
Aug 11, 2021

Conversation

davidpdrsn
Copy link
Contributor

Fixes #72

This adds Pool::get_owned which returns Result<PooledConnection<'static, M>, _>. The 'static means this pool is "detached" from the lifetime of the pool itself and can thus be used where the lifetime the pool gets in the way.

Considerations I made:

  • Introduce a new connection type like OwnedPooledConnection<M> (similar to tokio::sync::OwnedSemaphorePermit). However I imagine having two types of connections will be when you have to abstract over OwnedPooledConnection and PooledConnection.
  • Make PooledConnection keep either a std::sync::Weak<PoolInner<M>> or a &'a PoolInner<M>. However that would require calling Arc::upgrade for most operations and how would one handle the case where that returns None? I guess pancking is the only option but I don't think thats ideal. I think storing an owned PoolInner<M> is nicer and leads to fewer surprises, though it does make it possible to leak the pool.

I have verified that this works for my use-case.

Copy link
Owner

@djc djc left a comment

Choose a reason for hiding this comment

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

This looks good modulo some minor nits. Thanks, and sorry for the long wait.

bb8/src/inner.rs Show resolved Hide resolved
bb8/src/api.rs Outdated Show resolved Hide resolved
bb8/src/api.rs Outdated Show resolved Hide resolved
davidpdrsn and others added 2 commits August 9, 2021 10:05
Co-authored-by: Dirkjan Ochtman <dirkjan@ochtman.nl>
@davidpdrsn
Copy link
Contributor Author

Ready for another review!

@davidpdrsn davidpdrsn requested a review from djc August 9, 2021 08:06
@djc djc merged commit a34763c into djc:main Aug 11, 2021
@djc
Copy link
Owner

djc commented Aug 11, 2021

Thanks!

@djc
Copy link
Owner

djc commented Aug 11, 2021

I've published bb8 0.7.1.

@davidpdrsn davidpdrsn deleted the weak-connection branch August 11, 2021 08:41
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.

Use Weak for PooledConnection's Pool ref?
2 participants