Class: Aw::Fork
- Inherits:
-
Object
- Object
- Aw::Fork
- Defined in:
- lib/aw/fork.rb
Overview
The Fork class.
Instance Attribute Summary collapse
-
#read ⇒ IO
readonly
The read endpoint.
-
#write ⇒ IO
readonly
The write endpoint.
Instance Method Summary collapse
-
#call(&block) ⇒ #object_id
Run the block inside a subprocess, and return the value.
-
#initialize(read, write) ⇒ Fork
constructor
Initialize the class.
Constructor Details
#initialize(read, write) ⇒ Fork
Initialize the class.
12 13 14 15 16 17 18 |
# File 'lib/aw/fork.rb', line 12 def initialize(read, write) # Currently, not available on all platforms. raise 'fork() unimplemented' unless ::Process.respond_to?(:fork) @read = read @write = write end |
Instance Attribute Details
#read ⇒ IO (readonly)
Returns The read endpoint.
23 24 25 |
# File 'lib/aw/fork.rb', line 23 def read @read end |
#write ⇒ IO (readonly)
Returns The write endpoint.
28 29 30 |
# File 'lib/aw/fork.rb', line 28 def write @write end |
Instance Method Details
#call(&block) ⇒ #object_id
Run the block inside a subprocess, and return the value.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/aw/fork.rb', line 33 def call(*, **, &block) pid = fork_and_return_pid(&block) write.close result = read.read ::Process.wait(pid) # rubocop:disable MarshalLoad ::Marshal.load(result).tap do |r| raise r if r.is_a?(::Exception) end # rubocop:enable MarshalLoad end |