Class: GRPC::Notifier

Inherits:
Object
  • Object
show all
Defined in:
src/ruby/lib/grpc/notifier.rb

Overview

Notifier is useful high-level synchronization primitive.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNotifier

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

#notifiedObject (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

#payloadObject (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

#waitObject



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