Class: Applitools::Selenium::VGThreadPool

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/applitools/selenium/visual_grid/thread_pool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#concurrencyObject

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

#startObject



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

#stopObject



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

Returns:

  • (Boolean)


47
48
49
# File 'lib/applitools/selenium/visual_grid/thread_pool.rb', line 47

def stopped?
  @semaphore.synchronize { @stopped }
end