Class: ConcurrentNode
Instance Attribute Summary collapse
-
#instance ⇒ Object
Returns the value of attribute instance.
Attributes inherited from Node
#after_list, #before_list, #code_block, #commands, #exec_block, #id, #is_concurrently, #is_safely, #name, #node_list, #parent
Instance Method Summary collapse
- #draw_block(graph) ⇒ Object
-
#initialize(parent, block) ⇒ ConcurrentNode
constructor
A new instance of ConcurrentNode.
- #run(instance) ⇒ Object
Methods inherited from Node
#after_exec, #before_exec, #draw_after_blocks, #draw_before_blocks, #draw_child_nodes, #init_time, #paint, #print_tree
Constructor Details
#initialize(parent, block) ⇒ ConcurrentNode
Returns a new instance of ConcurrentNode.
7 8 9 |
# File 'lib/tree_building/concurrent_node.rb', line 7 def initialize (parent, block) super(parent, block) end |
Instance Attribute Details
#instance ⇒ Object
Returns the value of attribute instance.
5 6 7 |
# File 'lib/tree_building/concurrent_node.rb', line 5 def instance @instance end |
Instance Method Details
#draw_block(graph) ⇒ Object
29 30 31 32 |
# File 'lib/tree_building/concurrent_node.rb', line 29 def draw_block(graph) graph.component << graph.node(self.id) graph.node(self.id).label('Concurrently') end |
#run(instance) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tree_building/concurrent_node.rb', line 11 def run(instance) pids = [] init_time before_exec(instance, @total_time) node_list.each do |node| pids << fork do @total_time[:exec].push(node.run(instance)) end end pids.each{|pid| Process.waitpid(pid)} after_exec(instance, @total_time) @total_time end |