Class: Applitools::Selenium::VGThreadPool
- Inherits:
-
Object
- Object
- Applitools::Selenium::VGThreadPool
- Extended by:
- Forwardable
- Defined in:
- lib/applitools/selenium/visual_grid/thread_pool.rb
Instance Attribute Summary collapse
-
#concurrency ⇒ Object
Returns the value of attribute concurrency.
Instance Method Summary collapse
-
#initialize(concurrency = 10) ⇒ VGThreadPool
constructor
A new instance of VGThreadPool.
- #on_next_task_needed(&block) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #stopped? ⇒ Boolean
Constructor Details
#initialize(concurrency = 10) ⇒ VGThreadPool
Returns a new instance of VGThreadPool.
10 11 12 13 14 15 16 17 |
# File 'lib/applitools/selenium/visual_grid/thread_pool.rb', line 10 def initialize(concurrency = 10) self.concurrency = concurrency @stopped = true @thread_group = ThreadGroup.new @semaphore = Mutex.new @next_task_block = nil @watchdog = nil end |
Instance Attribute Details
#concurrency ⇒ Object
Returns the value of attribute concurrency.
7 8 9 |
# File 'lib/applitools/selenium/visual_grid/thread_pool.rb', line 7 def concurrency @concurrency end |
Instance Method Details
#on_next_task_needed(&block) ⇒ Object
19 20 21 |
# File 'lib/applitools/selenium/visual_grid/thread_pool.rb', line 19 def on_next_task_needed(&block) @next_task_block = block if block_given? end |
#start ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/applitools/selenium/visual_grid/thread_pool.rb', line 23 def start @semaphore.synchronize { @stopped = false } init_or_renew_threads @watchdog = Thread.new do catch(:exit) do loop do throw :exit if stopped? sleep 5 init_or_renew_threads end end end end |
#stop ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/applitools/selenium/visual_grid/thread_pool.rb', line 37 def stop @watchdog.exit @semaphore.synchronize do @stopped = true end @thread_group.list.each(&:join) stopped? end |
#stopped? ⇒ Boolean
46 47 48 |
# File 'lib/applitools/selenium/visual_grid/thread_pool.rb', line 46 def stopped? @semaphore.synchronize { @stopped } end |