Class: Bones::RPC::Node::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/bones/rpc/node/registry.rb

Overview

Since:

  • 1.0.0

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.

Since:

  • 1.0.0



7
8
9
# File 'lib/bones/rpc/node/registry.rb', line 7

def initialize
  @registry = {}
end

Instance Method Details

#flush(exception = Errors::ConnectionFailure.new("Socket closed")) ⇒ Object

Since:

  • 1.0.0



11
12
13
14
15
16
17
18
19
# File 'lib/bones/rpc/node/registry.rb', line 11

def flush(exception = Errors::ConnectionFailure.new("Socket closed"))
  return true if @registry.empty?
  @registry.each do |channel, futures|
    futures.each do |id, future|
      future.signal(FutureValue.new(exception)) rescue nil
    end
  end
  @registry.clear
end

#get(channel, id) ⇒ Object

Since:

  • 1.0.0



21
22
23
# File 'lib/bones/rpc/node/registry.rb', line 21

def get(channel, id)
  (@registry[channel] ||= {}).delete(id)
end

#set(channel, id, future) ⇒ Object

Since:

  • 1.0.0



25
26
27
# File 'lib/bones/rpc/node/registry.rb', line 25

def set(channel, id, future)
  (@registry[channel] ||= {})[id] = future
end