Class: GRPC::Notifier
- Inherits:
-
Object
- Object
- GRPC::Notifier
- Defined in:
- lib/grpc/notifier.rb
Overview
Notifier is useful high-level synchronization primitive.
Instance Attribute Summary collapse
-
#notified ⇒ Object
(also: #notified?)
readonly
Returns the value of attribute notified.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
Instance Method Summary collapse
-
#initialize ⇒ Notifier
constructor
A new instance of Notifier.
- #notify(payload) ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize ⇒ Notifier
Returns a new instance of Notifier.
37 38 39 40 41 42 |
# File 'lib/grpc/notifier.rb', line 37 def initialize @mutex = Mutex.new @cvar = ConditionVariable.new @notified = false @payload = nil end |
Instance Attribute Details
#notified ⇒ Object (readonly) Also known as: notified?
Returns the value of attribute notified.
34 35 36 |
# File 'lib/grpc/notifier.rb', line 34 def notified @notified end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
34 35 36 |
# File 'lib/grpc/notifier.rb', line 34 def payload @payload end |
Instance Method Details
#notify(payload) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/grpc/notifier.rb', line 50 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
44 45 46 47 48 |
# File 'lib/grpc/notifier.rb', line 44 def wait @mutex.synchronize do @cvar.wait(@mutex) until notified? end end |