Class: DirectoryWatcher::Threaded::ThreadContainer
- Inherits:
-
Struct
- Object
- Struct
- DirectoryWatcher::Threaded::ThreadContainer
- Defined in:
- lib/directory_watcher/threaded.rb
Instance Attribute Summary collapse
-
#continue_on_error ⇒ Object
Returns the value of attribute continue_on_error.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#iterations ⇒ Object
Returns the value of attribute iterations.
-
#maximum_iterations ⇒ Object
Returns the value of attribute maximum_iterations.
-
#running ⇒ Object
(also: #running?)
Returns the value of attribute running.
-
#thread ⇒ Object
Returns the value of attribute thread.
-
#working ⇒ Object
Returns the value of attribute working.
Instance Method Summary collapse
- #do_work(threaded) ⇒ Object
- #finished_iterations? ⇒ Boolean
- #join(limit = nil) ⇒ Object
- #run(threaded) ⇒ Object
- #start(threaded) ⇒ Object
- #stop ⇒ Object
Instance Attribute Details
#continue_on_error ⇒ Object
Returns the value of attribute continue_on_error
212 213 214 |
# File 'lib/directory_watcher/threaded.rb', line 212 def continue_on_error @continue_on_error end |
#interval ⇒ Object
Returns the value of attribute interval
212 213 214 |
# File 'lib/directory_watcher/threaded.rb', line 212 def interval @interval end |
#iterations ⇒ Object
Returns the value of attribute iterations
212 213 214 |
# File 'lib/directory_watcher/threaded.rb', line 212 def iterations @iterations end |
#maximum_iterations ⇒ Object
Returns the value of attribute maximum_iterations
212 213 214 |
# File 'lib/directory_watcher/threaded.rb', line 212 def maximum_iterations @maximum_iterations end |
#running ⇒ Object Also known as: running?
Returns the value of attribute running
212 213 214 |
# File 'lib/directory_watcher/threaded.rb', line 212 def running @running end |
#thread ⇒ Object
Returns the value of attribute thread
212 213 214 |
# File 'lib/directory_watcher/threaded.rb', line 212 def thread @thread end |
#working ⇒ Object
Returns the value of attribute working
212 213 214 |
# File 'lib/directory_watcher/threaded.rb', line 212 def working @working end |
Instance Method Details
#do_work(threaded) ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/directory_watcher/threaded.rb', line 256 def do_work( threaded ) if working then threaded.run if maximum_iterations self.iterations += 1 if finished_iterations? self.running = false end end end end |
#finished_iterations? ⇒ Boolean
269 270 271 272 |
# File 'lib/directory_watcher/threaded.rb', line 269 def finished_iterations? return true if maximum_iterations and (iterations >= maximum_iterations) return false end |
#join(limit = nil) ⇒ Object
251 252 253 254 |
# File 'lib/directory_watcher/threaded.rb', line 251 def join( limit = nil ) return if thread.nil? limit ? thread.join(limit) : thread.join end |
#run(threaded) ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/directory_watcher/threaded.rb', line 227 def run( threaded ) loop do begin break unless running? do_work( threaded ) sleep interval if running? rescue SystemExit; raise rescue Exception => err if continue_on_error $stderr.puts err else $stderr.puts err raise err end end end ensure if threaded.respond_to?(:after_stopping) and !self.running threaded.after_stopping end self.running = false end |
#start(threaded) ⇒ Object
213 214 215 216 217 218 219 220 |
# File 'lib/directory_watcher/threaded.rb', line 213 def start( threaded ) self.working = true self.running = true self.iterations = 0 self.thread = Thread.new { run threaded } Thread.pass end |
#stop ⇒ Object
222 223 224 225 |
# File 'lib/directory_watcher/threaded.rb', line 222 def stop self.running = false thread.wakeup end |