RFC: Implement ConnectionPool#then
#138
Merged
+7
−0
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.
What?
In Ruby 2.5, Object#then was added as a standard way to "yield self" to the caller. This convention is useful since it allows for library maintainers to abstract access to a value.
For example, Concurrent#Promise implements
.then
in a way which allow access to a concurrently resolved value:The Problem
When using
connection-pool
in the wild, on multiple occasions I have been unable to directly pass aConnectionPool
wrapped Redis to a library. Most recently, we can't use aConnectionPool
Redis inrack-mini-profiler
since it, rightfully, assumes the Redis connection is an actualRedis::Client
.Unfortunately, currently library maintainers like
rack-mini-profiler
have no easy way to support both rawRedis::Client
and aConnectionPool
Redis. In order to be compatible with both, they would have to specifically check if the object responds to.with
, and add conditional codepaths. Some library actually do this, which is nice! But overall, it's painful to have to support two codepaths.Proposed Solution
By adding
.then
, gems would have a way to support both raw Redis and CP Redis using the same codepath, no conditionals. Offering this API offers an easily adoptable and ergonomic interface for Ruby 2.5+:Thoughts?