Class: Open4::ThreadEnsemble
Instance Attribute Summary collapse
-
#threads ⇒ Object
readonly
Returns the value of attribute threads.
Instance Method Summary collapse
- #add_thread(*a, &b) ⇒ Object
- #all_done ⇒ Object
-
#initialize(cid) ⇒ ThreadEnsemble
constructor
A new instance of ThreadEnsemble.
-
#killall ⇒ Object
take down process more nicely.
- #run ⇒ Object
Constructor Details
#initialize(cid) ⇒ ThreadEnsemble
Returns a new instance of ThreadEnsemble.
155 156 157 158 |
# File 'lib/vendor/open4/lib/open4.rb', line 155 def initialize cid @cid, @threads, @argv, @done, @running = cid, [], [], Queue.new, false @killed = false end |
Instance Attribute Details
#threads ⇒ Object (readonly)
Returns the value of attribute threads.
153 154 155 |
# File 'lib/vendor/open4/lib/open4.rb', line 153 def threads @threads end |
Instance Method Details
#add_thread(*a, &b) ⇒ Object
160 161 162 |
# File 'lib/vendor/open4/lib/open4.rb', line 160 def add_thread *a, &b @running ? raise : (@argv << [a, b]) end |
#all_done ⇒ Object
201 202 203 |
# File 'lib/vendor/open4/lib/open4.rb', line 201 def all_done @threads.size.times{ @done.pop } end |
#killall ⇒ Object
take down process more nicely
167 168 169 170 171 172 173 174 175 |
# File 'lib/vendor/open4/lib/open4.rb', line 167 def killall c = Thread.critical return nil if @killed Thread.critical = true (@threads - [Thread.current]).each{|t| t.kill rescue nil} @killed = true ensure Thread.critical = c end |
#run ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/vendor/open4/lib/open4.rb', line 177 def run @running = true begin @argv.each do |a, b| @threads << Thread.new(*a) do |*a| begin b[*a] ensure killall rescue nil if $! @done.push Thread.current end end end rescue killall raise ensure all_done end @threads.map{|t| t.value} end |