Class: Garden::Rows
- Inherits:
-
Object
- Object
- Garden::Rows
- Defined in:
- lib/rows.rb,
lib/rows_paths.rb
Overview
- Author
-
lp ([email protected])
- Copyright
-
2008 Louis-Philippe Perron - Released under the terms of the MIT license
:title:Rows
Defined Under Namespace
Modules: Paths
Constant Summary
Constants included from Toolshed
Instance Attribute Summary collapse
-
#pids ⇒ Object
readonly
Returns the value of attribute pids.
Instance Method Summary collapse
-
#initialize(rows, init_timeout, garden_pid, gardener_block) ⇒ Rows
constructor
The
new
class method initializes the Rows.
Methods included from Toolshed
#add_readable, #add_writable, block_size=, #my_socket_path, #read_message_block, #read_raw, #remove_writable, #set_my_socket_as_a, #socket_duplex, #socket_recv, #socket_send, #write_raw
Methods included from Paths
#all, #crop, #init, #quit, #sprout
Constructor Details
#initialize(rows, init_timeout, garden_pid, gardener_block) ⇒ Rows
The new
class method initializes the Rows. As part of the Abundance lib, Rows is not initialized directly, but rather as a side effect of the Gardener’s initialization, through the rows
Garden instance method. Its instance resides in the @garden_rows Gardener’s instance variable. Its real muscles are inaccessibles from instance method intervention, because of its nature as a forked Ruby process.
Parameter
-
rows = garden rows number, the number of concurent threads
-
init_timeout = allow to pause execution to allow for larger garden rows to initialize
-
garden_pid = the parent Garden’s pid, for loopback communication purpose
Example
rows = Rows.new(4,2) { grow_block }
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rows.rb', line 43 def initialize(rows,init_timeout,garden_pid,gardener_block) @pids = [] rows.times do @pids << fork do set_my_socket_as_a(:row,garden_pid) t1 = Thread.new do gardener_block.call end t2 = Thread.new do loop do if $seed.nil? = socket_duplex([:row,:row,@my_socket_path,@garden_path]) case [1] when :sprout sprout() when :all all() when :wait = socket_recv case [1] when :sprout sprout() when :all all() when :init init when :quit quit end when :init init when :quit quit end elsif ! $seed[:success].nil? crop else t1.run end end end t2.join end end sleep init_timeout end |
Instance Attribute Details
#pids ⇒ Object (readonly)
Returns the value of attribute pids.
27 28 29 |
# File 'lib/rows.rb', line 27 def pids @pids end |