Class: GRPC::Notifier
- Inherits:
-
Object
- Object
- GRPC::Notifier
- Defined in:
- src/ruby/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.
22 23 24 25 26 27 |
# File 'src/ruby/lib/grpc/notifier.rb', line 22 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.
19 20 21 |
# File 'src/ruby/lib/grpc/notifier.rb', line 19 def notified @notified end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
19 20 21 |
# File 'src/ruby/lib/grpc/notifier.rb', line 19 def payload @payload end |
Instance Method Details
#notify(payload) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'src/ruby/lib/grpc/notifier.rb', line 35 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
29 30 31 32 33 |
# File 'src/ruby/lib/grpc/notifier.rb', line 29 def wait @mutex.synchronize do @cvar.wait(@mutex) until notified? end end |