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.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 80 def initialize(forkset) @parent_read, @child_write = IO.pipe @child_read, @parent_write = IO.pipe @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
106 107 108 109 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 106 def close send(:close) @parent_write.close end |
#eof? ⇒ Boolean
137 138 139 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 137 def eof? write_io.closed? end |
#fork? ⇒ Boolean
125 126 127 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 125 def fork? @in_fork end |
#goodbye ⇒ Object
111 112 113 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 111 def goodbye read_io.close unless read_io.closed? end |
#read_io ⇒ Object
129 130 131 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 129 def read_io fork? ? @child_read : @parent_read end |
#recv ⇒ Object
145 146 147 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 145 def recv (read_io) end |
#recv_message(io) ⇒ Object
120 121 122 123 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 120 def (io) length, = *io.read(8).unpack('Q') Marshal.load(io.read(length)) # rubocop:disable Security/MarshalLoad end |
#send(*msg) ⇒ Object
141 142 143 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 141 def send(*msg) (write_io, msg) end |
#send_message(io, msg) ⇒ Object
115 116 117 118 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 115 def (io, msg) msg = Marshal.dump(msg) io.write([msg.length].pack('Q') + msg) end |
#wait ⇒ Object
149 150 151 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 149 def wait Process.waitpid(@pid, Process::WNOHANG) end |
#write_io ⇒ Object
133 134 135 |
# File 'opal/lib/opal/builder_scheduler/prefork.rb', line 133 def write_io fork? ? @child_write : @parent_write end |