Class: Contrails::Semaphore

Inherits:
Object
  • Object
show all
Includes:
EventMachine::Deferrable
Defined in:
lib/contrails/semaphore.rb

Instance Method Summary collapse

Constructor Details

#initialize(n, results) ⇒ Semaphore

Returns a new instance of Semaphore.



8
9
10
11
12
# File 'lib/contrails/semaphore.rb', line 8

def initialize(n, results)
  @value = n
  @results = results
  @mutex = Mutex.new
end

Instance Method Details

#signalObject



14
15
16
17
18
19
20
# File 'lib/contrails/semaphore.rb', line 14

def signal
  @mutex.synchronize do
    if(@value -= 1) == 0
      self.succeed(*Contrails::Helpers.unwrap_array(@results))  
    end
  end
end