Class: Procrastinate::IPC::Endpoint::Anonymous::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/procrastinate/ipc/endpoint.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pipe) ⇒ Server

Returns a new instance of Server.



61
62
63
64
# File 'lib/procrastinate/ipc/endpoint.rb', line 61

def initialize(pipe)
  @pipe = pipe
  @waiting = Array.new
end

Instance Attribute Details

#pipeObject (readonly)

Returns the value of attribute pipe.



59
60
61
# File 'lib/procrastinate/ipc/endpoint.rb', line 59

def pipe
  @pipe
end

#waitingObject (readonly)

Returns the value of attribute waiting.



60
61
62
# File 'lib/procrastinate/ipc/endpoint.rb', line 60

def waiting
  @waiting
end

Instance Method Details

#receive(timeout = nil) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/procrastinate/ipc/endpoint.rb', line 66

def receive(timeout=nil)
  return waiting.shift if waiting?
  
  loop do
    buffer = pipe.read_nonblock(1024*1024*1024)
  
    while buffer.size > 0
      size = buffer.slice!(0...4).unpack('l').first
      waiting << buffer.slice!(0...size)
    end
  
    return waiting.shift if waiting?
  end
end

#select_iosObject

Return underlying IOs for select.



90
91
92
# File 'lib/procrastinate/ipc/endpoint.rb', line 90

def select_ios
  [@pipe]
end

#waiting?Boolean

True if there are queued messages in the Endpoint stack. If this is false, a receive might block.

Returns:

  • (Boolean)


84
85
86
# File 'lib/procrastinate/ipc/endpoint.rb', line 84

def waiting?
  not waiting.empty?
end