Class: Bitcoin::Wallet::Publisher

Inherits:
Concurrent::Actor::RestartingContext
  • Object
show all
Defined in:
lib/bitcoin/wallet/publisher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePublisher

Returns a new instance of Publisher.



8
9
10
# File 'lib/bitcoin/wallet/publisher.rb', line 8

def initialize
  @receivers = {}
end

Instance Attribute Details

#receiversObject (readonly)

Returns the value of attribute receivers.



6
7
8
# File 'lib/bitcoin/wallet/publisher.rb', line 6

def receivers
  @receivers
end

Instance Method Details

#on_message(message) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bitcoin/wallet/publisher.rb', line 12

def on_message(message)
  case message
  when :unsubscribe
    receivers.each { |receiver| receiver.delete(envelope.sender) }
  when Array
    if message[0] == :subscribe
      if envelope.sender.is_a? Concurrent::Actor::Reference
        receivers[message[1].name] ||= []
        receivers[message[1].name] << envelope.sender
      end
    elsif message[0] == :subscribe?
      receivers[message[1].name]&.include?(envelope.sender)
    elsif message[0] == :unsubscribe
      receivers.delete(message[1].name)
    end
  else
    receivers[message&.class&.name]&.each { |r| r << message }
  end
end