Class: Procrastinate::IPC::Endpoint::Anonymous::Server
- Inherits:
-
Object
- Object
- Procrastinate::IPC::Endpoint::Anonymous::Server
- Defined in:
- lib/procrastinate/ipc/endpoint.rb
Instance Attribute Summary collapse
-
#pipe ⇒ Object
readonly
Returns the value of attribute pipe.
-
#waiting ⇒ Object
readonly
Returns the value of attribute waiting.
Instance Method Summary collapse
-
#initialize(pipe) ⇒ Server
constructor
A new instance of Server.
- #receive(timeout = nil) ⇒ Object
-
#select_ios ⇒ Object
Return underlying IOs for select.
-
#waiting? ⇒ Boolean
True if there are queued messages in the Endpoint stack.
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
#pipe ⇒ Object (readonly)
Returns the value of attribute pipe.
59 60 61 |
# File 'lib/procrastinate/ipc/endpoint.rb', line 59 def pipe @pipe end |
#waiting ⇒ Object (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_ios ⇒ Object
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.
84 85 86 |
# File 'lib/procrastinate/ipc/endpoint.rb', line 84 def waiting? not waiting.empty? end |