Class: TRMNLP::BrowserPool
- Inherits:
-
Object
- Object
- TRMNLP::BrowserPool
- Defined in:
- lib/trmnlp/browser_pool.rb
Instance Method Summary collapse
-
#initialize(driver_factory:, max_size: 2) ⇒ BrowserPool
constructor
A new instance of BrowserPool.
- #shutdown ⇒ Object
- #with_driver ⇒ Object
Constructor Details
#initialize(driver_factory:, max_size: 2) ⇒ BrowserPool
Returns a new instance of BrowserPool.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/trmnlp/browser_pool.rb', line 5 def initialize(driver_factory:, max_size: 2) @driver_factory = driver_factory @max_size = max_size @drivers = [] @available = Queue.new @mutex = Mutex.new @shutdown = false at_exit { shutdown } end |
Instance Method Details
#shutdown ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/trmnlp/browser_pool.rb', line 23 def shutdown @mutex.synchronize do return if @shutdown @shutdown = true @drivers.each do |driver| driver.quit rescue StandardError nil end @drivers.clear end end |
#with_driver ⇒ Object
16 17 18 19 20 21 |
# File 'lib/trmnlp/browser_pool.rb', line 16 def with_driver driver = checkout yield driver ensure checkin(driver) if driver end |