Class: Opal::BuilderScheduler::Prefork::Fork
- Inherits:
-
Object
- Object
- Opal::BuilderScheduler::Prefork::Fork
- Defined in:
- opal/lib/opal/builder_scheduler/prefork.rb
Instance Method Summary collapse
- #close ⇒ Object
- #eof? ⇒ Boolean
- #fork? ⇒ Boolean
- #goodbye ⇒ Object
-
#initialize(forkset) ⇒ Fork
constructor
A new instance of Fork.
- #read_io ⇒ Object
- #recv ⇒ Object
- #recv_message(io) ⇒ Object
- #send(*msg) ⇒ Object
- #send_message(io, msg) ⇒ Object
- #wait ⇒ Object
- #write_io ⇒ Object
Constructor Details
#initialize(forkset) ⇒ Fork
Returns a new instance of Fork.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 133 def initialize(forkset) @parent_read, @child_write = IO.pipe(binmode: true) @child_read, @parent_write = IO.pipe(binmode: true) @forkset = forkset @in_fork = false @pid = fork do @in_fork = true begin @parent_read.close @parent_write.close yield(self) rescue => error send(:exception, error) ensure send(:close) unless write_io.closed? @child_write.close end end @child_read.close @child_write.close end |
Instance Method Details
#close ⇒ Object
159 160 161 162 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 159 def close send(:close) @parent_write.close end |
#eof? ⇒ Boolean
190 191 192 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 190 def eof? write_io.closed? end |
#fork? ⇒ Boolean
178 179 180 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 178 def fork? @in_fork end |
#goodbye ⇒ Object
164 165 166 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 164 def goodbye read_io.close unless read_io.closed? end |
#read_io ⇒ Object
182 183 184 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 182 def read_io fork? ? @child_read : @parent_read end |
#recv ⇒ Object
198 199 200 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 198 def recv (read_io) end |
#recv_message(io) ⇒ Object
173 174 175 176 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 173 def (io) length, = *io.read(8).unpack('Q') Marshal.load(io.read(length)) # rubocop:disable Security/MarshalLoad end |
#send(*msg) ⇒ Object
194 195 196 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 194 def send(*msg) (write_io, msg) end |
#send_message(io, msg) ⇒ Object
168 169 170 171 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 168 def (io, msg) msg = Marshal.dump(msg) io.write([msg.length].pack('Q') + msg) end |
#wait ⇒ Object
202 203 204 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 202 def wait Process.waitpid(@pid, Process::WNOHANG) end |
#write_io ⇒ Object
186 187 188 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 186 def write_io fork? ? @child_write : @parent_write end |