Method: Sequel::ShardedTimedQueueConnectionPool#all_connections
- Defined in:
- lib/sequel/connection_pool/sharded_timed_queue.rb
#all_connections ⇒ Object
Yield all of the available connections, and the one currently allocated to this thread (if one is allocated). This will not yield connections currently allocated to other threads, as it is not safe to operate on them.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/sequel/connection_pool/sharded_timed_queue.rb', line 60 def all_connections thread = Sequel.current sync{@queues.to_a}.each do |server, queue| if conn = owned_connection(thread, server) yield conn end # Use a hash to record all connections already seen. As soon as we # come across a connection we've already seen, we stop the loop. conns = {} conns.compare_by_identity while true conn = nil begin break unless (conn = queue.pop(timeout: 0)) && !conns[conn] conns[conn] = true yield conn ensure queue.push(conn) if conn end end end nil end |