Class: BioDSL::Fork
- Inherits:
-
Object
- Object
- BioDSL::Fork
- Defined in:
- lib/BioDSL/fork.rb
Overview
Class containing methods to fork in an objective oriented manner.
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Class Method Summary collapse
-
.execute(&block) ⇒ Fork
Class method to execute a block in a seperate process.
Instance Method Summary collapse
-
#execute ⇒ Object
Execute the block in a separate process.
-
#initialize(&block) ⇒ Fork
constructor
Constructor for Fork.
-
#read ⇒ Object
Read object from forked process.
-
#running? ⇒ Bool
Determines if process is running.
-
#wait ⇒ Object
Wait for forked process.
-
#write(obj) ⇒ Object
Write object to forked process.
Constructor Details
#initialize(&block) ⇒ Fork
Constructor for Fork.
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/BioDSL/fork.rb', line 54 def initialize(&block) fail ArgumentError, 'No block given' unless block @parent = true @alive = false @pid = nil @input = nil @output = nil @block = block end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
35 36 37 |
# File 'lib/BioDSL/fork.rb', line 35 def input @input end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
35 36 37 |
# File 'lib/BioDSL/fork.rb', line 35 def output @output end |
Class Method Details
.execute(&block) ⇒ Fork
Class method to execute a block in a seperate process.
42 43 44 45 |
# File 'lib/BioDSL/fork.rb', line 42 def self.execute(&block) parent = new(&block) parent.execute end |
Instance Method Details
#execute ⇒ Object
Execute the block in a separate process.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/BioDSL/fork.rb', line 66 def execute @alive = true child_read, parent_write = BioDSL::Stream.pipe parent_read, child_write = BioDSL::Stream.pipe pid = fork_process(child_read, child_write, parent_read, parent_write) child_write.close child_read.close @pid = pid @input = parent_read @output = parent_write self end |
#read ⇒ Object
Read object from forked process.
94 95 96 97 98 |
# File 'lib/BioDSL/fork.rb', line 94 def read fail BioDSL::ForkError, 'Not running' unless running? @input.read end |
#running? ⇒ Bool
Determines if process is running.
87 88 89 |
# File 'lib/BioDSL/fork.rb', line 87 def running? @pid end |