Class: Agent::Notifier
- Inherits:
-
Object
- Object
- Agent::Notifier
- Defined in:
- lib/agent/notifier.rb
Instance Attribute Summary collapse
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
Instance Method Summary collapse
-
#initialize ⇒ Notifier
constructor
A new instance of Notifier.
- #notified? ⇒ Boolean
- #notify(payload) ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize ⇒ Notifier
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
#payload ⇒ Object (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
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 |
#wait ⇒ Object
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 |