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.



37
38
39
40
41
42
# File 'src/ruby/lib/grpc/notifier.rb', line 37

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.



34
35
36
# File 'src/ruby/lib/grpc/notifier.rb', line 34

def notified
  @notified
end

#payloadObject (readonly)

Returns the value of attribute payload.



34
35
36
# File 'src/ruby/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 'src/ruby/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

#waitObject



44
45
46
47
48
# File 'src/ruby/lib/grpc/notifier.rb', line 44

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