@@ -53,7 +53,7 @@ def async_executor; end
53
53
# handle cases in which there are more threads than connections: if all
54
54
# connections have been checked out, and a thread tries to checkout a
55
55
# connection anyway, then ConnectionPool will wait until some other thread
56
- # has checked in a connection.
56
+ # has checked in a connection, or the +checkout_timeout+ has expired .
57
57
#
58
58
# == Obtaining (checking out) a connection
59
59
#
@@ -78,6 +78,12 @@ def async_executor; end
78
78
# Connections in the pool are actually AbstractAdapter objects (or objects
79
79
# compatible with AbstractAdapter's interface).
80
80
#
81
+ # While a thread has a connection checked out from the pool using one of the
82
+ # above three methods, that connection will automatically be the one used
83
+ # by ActiveRecord queries executing on that thread. It is not required to
84
+ # explicitly pass the checked out connection to Rails models or queries, for
85
+ # example.
86
+ #
81
87
# == Options
82
88
#
83
89
# There are several connection-pooling-related options that you can add to
@@ -206,10 +212,15 @@ def release_connection(owner_thread = ActiveSupport::IsolatedExecutionState.cont
206
212
end
207
213
end
208
214
209
- # If a connection obtained through #connection or #with_connection methods
210
- # already exists yield it to the block. If no such connection
211
- # exists checkout a connection, yield it to the block, and checkin the
212
- # connection when finished.
215
+ # Yields a connection from the connection pool to the block. If no connection
216
+ # is already checked out by the current thread, a connection will be checked
217
+ # out from the pool, yielded to the block, and then returned to the pool when
218
+ # the block is finished. If a connection has already been checked out on the
219
+ # current thread, such as via #connection or #with_connection, that existing
220
+ # connection will be the one yielded and it will not be returned to the pool
221
+ # automatically at the end of the block; it is expected that such an existing
222
+ # connection will be properly returned to the pool by the code that checked
223
+ # it out.
213
224
def with_connection
214
225
unless conn = @thread_cached_conns [ connection_cache_key ( ActiveSupport ::IsolatedExecutionState . context ) ]
215
226
conn = connection
0 commit comments