Class: OMQ::Ractor::SocketSet

Inherits:
Array
  • Object
show all
Defined in:
lib/omq/ractor.rb

Overview

Array of SocketProxy objects with a port→proxy lookup for Ractor.select results.

Instance Method Summary collapse

Constructor Details

#initialize(proxies) ⇒ SocketSet

Returns a new instance of SocketSet.

Parameters:

  • proxies (Array<SocketProxy>)

    socket proxies to include



297
298
299
300
301
302
303
304
305
306
307
# File 'lib/omq/ractor.rb', line 297

def initialize(proxies)
  super(proxies)
  @by_port = {}
  proxies.each do |proxy|
    begin
      @by_port[proxy.to_port] = proxy if proxy.to_port
    rescue ::Ractor::ClosedError
      # Skip non-readable proxies.
    end
  end
end

Instance Method Details

#socket_for(port) ⇒ SocketProxy?

Returns the SocketProxy whose input port matches port. Use after Ractor.select to map back to the proxy:

port, msg = Ractor.select(a.to_port, b.to_port)
source = sockets.socket_for(port)

Parameters:

  • port (Ractor::Port)

Returns:



319
320
321
# File 'lib/omq/ractor.rb', line 319

def socket_for(port)
  @by_port[port]
end