Module: Procrastinate::IPC::Endpoint

Defined in:
lib/procrastinate/ipc/endpoint.rb

Overview

A communication endpoint. This acts as a factory and hub for the whole IPC library.

Defined Under Namespace

Classes: Anonymous

Class Method Summary collapse

Class Method Details

.anonymousObject



6
7
8
# File 'lib/procrastinate/ipc/endpoint.rb', line 6

def anonymous
  Anonymous.new
end

.select(read_array, timeout = nil) ⇒ Object

Works the same as IO.select, only that it doesn’t care about write and error readiness, only read. You can mix IPC::Endpoints and normal IO instances freely.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/procrastinate/ipc/endpoint.rb', line 15

def select(read_array, timeout=nil)
  # This maps real system IO instances to wrapper objects. Return the thing
  # to the right if IO.select returns the thing to the left. 
  mapping = Hash.new
  waiting = []
  
  read_array.each { |io_or_endpoint| 
    if io_or_endpoint.respond_to?(:select_ios)
      waiting << io_or_endpoint if io_or_endpoint.waiting?
      
      io_or_endpoint.select_ios.each do |io|
        mapping[io] = io_or_endpoint
      end
    else
      mapping[io_or_endpoint] = io_or_endpoint
    end
  }
  
  return waiting unless waiting.empty?
  
  system_io = IO.select(mapping.keys, nil, nil, timeout)
  if system_io
    return system_io.first.
      # Map returned selectors to their object counterparts and then only
      # return once (if more than one was returned).
      map { |e| mapping[e] }.uniq   
  end
end