Class: Capybara::Lockstep::Server

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/capybara-lockstep/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#log

Constructor Details

#initializeServer

Returns a new instance of Server.



6
7
8
9
10
# File 'lib/capybara-lockstep/server.rb', line 6

def initialize
  @job_count = 0
  @job_count_mutex = Mutex.new
  @idle_condition = ConditionVariable.new
end

Instance Attribute Details

#job_countObject

Returns the value of attribute job_count.



12
13
14
# File 'lib/capybara-lockstep/server.rb', line 12

def job_count
  @job_count
end

Instance Method Details

#start_work(tag) ⇒ Object



14
15
16
17
18
19
# File 'lib/capybara-lockstep/server.rb', line 14

def start_work(tag)
  job_count_mutex.synchronize do
    self.job_count += 1
    log("Started server work: #{tag} [#{job_count} server jobs]") if tag
  end
end

#stop_work(tag) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/capybara-lockstep/server.rb', line 21

def stop_work(tag)
  job_count_mutex.synchronize do
    self.job_count -= 1
    log("Stopped server work: #{tag} [#{job_count} server jobs]") if tag

    if job_count == 0
      idle_condition.broadcast
    end
  end
end

#synchronizeObject



32
33
34
35
36
37
38
# File 'lib/capybara-lockstep/server.rb', line 32

def synchronize
  job_count_mutex.synchronize do
    if job_count > 0
      idle_condition.wait(job_count_mutex)
    end
  end
end