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.
11 12 13 14 15 16 17 18 |
# File 'lib/applitools/selenium/visual_grid/thread_pool.rb', line 11 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.
8 9 10 |
# File 'lib/applitools/selenium/visual_grid/thread_pool.rb', line 8 def concurrency @concurrency end |
Instance Method Details
#on_next_task_needed(&block) ⇒ Object
20 21 22 |
# File 'lib/applitools/selenium/visual_grid/thread_pool.rb', line 20 def on_next_task_needed(&block) @next_task_block = block if block_given? end |
#start ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/applitools/selenium/visual_grid/thread_pool.rb', line 24 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
38 39 40 41 42 43 44 45 |
# File 'lib/applitools/selenium/visual_grid/thread_pool.rb', line 38 def stop @watchdog.exit @semaphore.synchronize do @stopped = true end @thread_group.list.each(&:join) stopped? end |
#stopped? ⇒ Boolean
47 48 49 |
# File 'lib/applitools/selenium/visual_grid/thread_pool.rb', line 47 def stopped? @semaphore.synchronize { @stopped } end |