Class: OMQ::Ractor::SocketSet
- Inherits:
-
Array
- Object
- Array
- OMQ::Ractor::SocketSet
- Defined in:
- lib/omq/ractor.rb
Overview
Array of SocketProxy objects with a port→proxy lookup for Ractor.select results.
Instance Method Summary collapse
-
#initialize(proxies) ⇒ SocketSet
constructor
A new instance of SocketSet.
-
#socket_for(port) ⇒ SocketProxy?
Returns the SocketProxy whose input port matches
port.
Constructor Details
#initialize(proxies) ⇒ SocketSet
Returns a new instance of SocketSet.
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)
319 320 321 |
# File 'lib/omq/ractor.rb', line 319 def socket_for(port) @by_port[port] end |