Class: S3Light::ConnectionsManager::Threaded
- Inherits:
-
Object
- Object
- S3Light::ConnectionsManager::Threaded
- Defined in:
- lib/s3-light/connections_manager/threaded.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(client, concurrency) ⇒ Threaded
constructor
A new instance of Threaded.
- #wait_to_finish ⇒ Object
- #with_connection ⇒ Object
Constructor Details
#initialize(client, concurrency) ⇒ Threaded
Returns a new instance of Threaded.
6 7 8 9 10 |
# File 'lib/s3-light/connections_manager/threaded.rb', line 6 def initialize(client, concurrency) @client = client @thread_pool = Concurrent::FixedThreadPool.new(concurrency) @connections = Concurrent::Array.new end |
Instance Method Details
#close ⇒ Object
25 26 27 28 |
# File 'lib/s3-light/connections_manager/threaded.rb', line 25 def close @connections.each(&:close) @connections = Concurrent::Array.new end |
#wait_to_finish ⇒ Object
30 31 32 33 |
# File 'lib/s3-light/connections_manager/threaded.rb', line 30 def wait_to_finish @thread_pool.shutdown @thread_pool.wait_for_termination end |
#with_connection ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/s3-light/connections_manager/threaded.rb', line 12 def with_connection @thread_pool.post do existing_connection = Thread.current[:connection] yield existing_connection if existing_connection new_connection = create_new_connection @connections << new_connection Thread.current[:connection] = new_connection yield new_connection end end |