Class: Agent::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/agent/notifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNotifier

Returns a new instance of Notifier.



5
6
7
8
9
10
# File 'lib/agent/notifier.rb', line 5

def initialize
  @mutex    = Mutex.new
  @cvar     = ConditionVariable.new
  @notified = false
  @payload  = nil
end

Instance Attribute Details

#payloadObject (readonly)

Returns the value of attribute payload.



3
4
5
# File 'lib/agent/notifier.rb', line 3

def payload
  @payload
end

Instance Method Details

#notified?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/agent/notifier.rb', line 12

def notified?
  @notified
end

#notify(payload) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/agent/notifier.rb', line 24

def notify(payload)
  @mutex.synchronize do
    return Error.new("already notified") if notified?
    @payload  = payload
    @notified = true
    @cvar.signal
    return nil
  end
end

#waitObject



16
17
18
19
20
21
22
# File 'lib/agent/notifier.rb', line 16

def wait
  @mutex.synchronize do
    until notified?
      @cvar.wait(@mutex)
    end
  end
end