Class: Hivent::AbstractSignal

Inherits:
Object
  • Object
show all
Defined in:
lib/hivent/abstract_signal.rb

Direct Known Subclasses

Redis::Signal, Spec::Signal

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ AbstractSignal

Returns a new instance of AbstractSignal.



8
9
10
11
12
# File 'lib/hivent/abstract_signal.rb', line 8

def initialize(name)
  @name        = name
  @producer    = nil
  @client_id   = Hivent::Config.client_id
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.



6
7
8
# File 'lib/hivent/abstract_signal.rb', line 6

def client_id
  @client_id
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/hivent/abstract_signal.rb', line 6

def name
  @name
end

#producerObject (readonly)

Returns the value of attribute producer.



6
7
8
# File 'lib/hivent/abstract_signal.rb', line 6

def producer
  @producer
end

Instance Method Details

#emit(payload, version:, cid: nil, key: nil) ⇒ Object



14
15
16
17
18
# File 'lib/hivent/abstract_signal.rb', line 14

def emit(payload, version:, cid: nil, key: nil)
  build_message(payload, cid, version).tap do |message|
    send_message(message, partition_key(key, message), version)
  end
end

#receive(version: nil, &block) ⇒ Object



20
21
22
23
# File 'lib/hivent/abstract_signal.rb', line 20

def receive(version: nil, &block)
  Hivent.emitter.on(event_name(version), &block)
  Hivent.emitter.events << { name: name, version: version }
end