Class: Strand::Atc

Inherits:
Object
  • Object
show all
Defined in:
lib/strand/atc.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Atc

Returns a new instance of Atc.



4
5
6
7
8
# File 'lib/strand/atc.rb', line 4

def initialize(options = {})
  @timeout  = options[:timeout]
  @cond     = ConditionVariable.new
  @states   = []
end

Instance Method Details

#signal(state) ⇒ Object



21
22
23
24
# File 'lib/strand/atc.rb', line 21

def signal(state)
  @states << state
  @cond.signal
end

#wait(state, timeout = nil) ⇒ Object

Wait for state to happen.



11
12
13
14
15
16
17
18
19
# File 'lib/strand/atc.rb', line 11

def wait(state, timeout = nil)
  return true if @states.include?(state)
  timeout ||= @timeout
  if timeout
    wait_with_timeout(state, timeout)
  else
    wait_without_timeout(state)
  end
end