Class: Aw::Fork Private
- Inherits:
-
Object
- Object
- Aw::Fork
- Defined in:
- lib/aw/fork.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The Fork class.
Instance Attribute Summary collapse
-
#read ⇒ IO
readonly
private
The read endpoint.
-
#write ⇒ IO
readonly
private
The write endpoint.
Instance Method Summary collapse
-
#call ⇒ #object_id
private
Runs the block inside a sub-process, and returns the computed value.
-
#initialize(read, write) ⇒ Fork
constructor
private
Initialize the class.
Constructor Details
#initialize(read, write) ⇒ Fork
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize the class.
14 15 16 17 18 19 20 |
# File 'lib/aw/fork.rb', line 14 def initialize(read, write) # Currently, not available on all platforms. raise ::NotImplementedError, "fork()" unless ::Process.respond_to?(:fork) @read = read @write = write end |
Instance Attribute Details
#read ⇒ IO (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The read endpoint.
25 26 27 |
# File 'lib/aw/fork.rb', line 25 def read @read end |
#write ⇒ IO (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The write endpoint.
30 31 32 |
# File 'lib/aw/fork.rb', line 30 def write @write end |
Instance Method Details
#call ⇒ #object_id
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Runs the block inside a sub-process, and returns the computed value.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/aw/fork.rb', line 39 def call(&) pid = fork_and_return_pid(&) write.close result = read.read ::Process.wait(pid) # rubocop:disable Security/MarshalLoad ::Marshal.load(result).tap { |r| raise r if r.is_a?(::Exception) } # rubocop:enable Security/MarshalLoad end |