@@ -161,6 +161,11 @@ impl Connection {
161
161
self . generation != current_generation
162
162
}
163
163
164
+ /// Checks if the connection is currently executing an operation.
165
+ pub ( super ) fn is_executing ( & self ) -> bool {
166
+ self . command_executing
167
+ }
168
+
164
169
/// Helper to create a `ConnectionCheckedOutEvent` for the connection.
165
170
pub ( super ) fn checked_out_event ( & self ) -> ConnectionCheckedOutEvent {
166
171
ConnectionCheckedOutEvent {
@@ -257,14 +262,13 @@ impl Connection {
257
262
stream : std:: mem:: replace ( & mut self . stream , AsyncStream :: Null ) ,
258
263
handler : self . handler . take ( ) ,
259
264
stream_description : self . stream_description . take ( ) ,
265
+ command_executing : self . command_executing ,
260
266
}
261
267
}
262
268
}
263
269
264
270
impl Drop for Connection {
265
271
fn drop ( & mut self ) {
266
- let command_executing = self . command_executing ;
267
-
268
272
// If the connection has a weak reference to a pool, that means that the connection is
269
273
// being dropped when it's checked out. If the pool is still alive, it
270
274
// should check itself back in. Otherwise, the connection should close
@@ -279,15 +283,9 @@ impl Drop for Connection {
279
283
if let Some ( strong_pool_ref) = weak_pool_ref. upgrade ( ) {
280
284
let dropped_connection_state = self . take ( ) ;
281
285
RUNTIME . execute ( async move {
282
- if command_executing {
283
- strong_pool_ref
284
- . dropped ( dropped_connection_state. into ( ) )
285
- . await ;
286
- } else {
287
- strong_pool_ref
288
- . check_in ( dropped_connection_state. into ( ) )
289
- . await ;
290
- }
286
+ strong_pool_ref
287
+ . check_in ( dropped_connection_state. into ( ) )
288
+ . await ;
291
289
} ) ;
292
290
} else {
293
291
self . close ( ConnectionClosedReason :: PoolClosed ) ;
@@ -315,6 +313,7 @@ struct DroppedConnectionState {
315
313
#[ derivative( Debug = "ignore" ) ]
316
314
handler : Option < Arc < dyn CmapEventHandler > > ,
317
315
stream_description : Option < StreamDescription > ,
316
+ command_executing : bool ,
318
317
}
319
318
320
319
impl Drop for DroppedConnectionState {
@@ -338,7 +337,7 @@ impl From<DroppedConnectionState> for Connection {
338
337
id : state. id ,
339
338
address : state. address . clone ( ) ,
340
339
generation : state. generation ,
341
- command_executing : false ,
340
+ command_executing : state . command_executing ,
342
341
stream : std:: mem:: replace ( & mut state. stream , AsyncStream :: Null ) ,
343
342
handler : state. handler . take ( ) ,
344
343
stream_description : state. stream_description . take ( ) ,
0 commit comments