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.



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

#concurrencyObject

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

#startObject



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

#stopObject



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

Returns:

  • (Boolean)


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

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