Class: ASIR::ThreadPool::Worker
- Inherits:
-
Object
- Object
- ASIR::ThreadPool::Worker
- Includes:
- AdditionalData, Initialization
- Defined in:
- lib/asir/thread_pool.rb
Instance Attribute Summary collapse
-
#run ⇒ Object
Returns the value of attribute run.
-
#running ⇒ Object
Returns the value of attribute running.
-
#stopped ⇒ Object
Returns the value of attribute stopped.
-
#stopping ⇒ Object
Returns the value of attribute stopping.
-
#thread ⇒ Object
Current Work and Thread.
-
#thread_pool ⇒ Object
Returns the value of attribute thread_pool.
-
#work ⇒ Object
Current Work and Thread.
-
#worker_id ⇒ Object
Returns the value of attribute worker_id.
Instance Method Summary collapse
- #inspect ⇒ Object
- #join(*args) ⇒ Object
- #kill!(*args) ⇒ Object
- #run! ⇒ Object
- #stop! ⇒ Object
- #to_s ⇒ Object
Methods included from Initialization
Methods included from AdditionalData
#[], #[]=, #_additional_data, #additional_data, #additional_data!, #additional_data=, included
Instance Attribute Details
#run ⇒ Object
Returns the value of attribute run.
168 169 170 |
# File 'lib/asir/thread_pool.rb', line 168 def run @run end |
#running ⇒ Object
Returns the value of attribute running.
168 169 170 |
# File 'lib/asir/thread_pool.rb', line 168 def running @running end |
#stopped ⇒ Object
Returns the value of attribute stopped.
168 169 170 |
# File 'lib/asir/thread_pool.rb', line 168 def stopped @stopped end |
#stopping ⇒ Object
Returns the value of attribute stopping.
168 169 170 |
# File 'lib/asir/thread_pool.rb', line 168 def stopping @stopping end |
#thread ⇒ Object
Current Work and Thread.
167 168 169 |
# File 'lib/asir/thread_pool.rb', line 167 def thread @thread end |
#thread_pool ⇒ Object
Returns the value of attribute thread_pool.
165 166 167 |
# File 'lib/asir/thread_pool.rb', line 165 def thread_pool @thread_pool end |
#work ⇒ Object
Current Work and Thread.
167 168 169 |
# File 'lib/asir/thread_pool.rb', line 167 def work @work end |
#worker_id ⇒ Object
Returns the value of attribute worker_id.
165 166 167 |
# File 'lib/asir/thread_pool.rb', line 165 def worker_id @worker_id end |
Instance Method Details
#inspect ⇒ Object
171 |
# File 'lib/asir/thread_pool.rb', line 171 def inspect; to_s; end |
#join(*args) ⇒ Object
200 201 202 203 |
# File 'lib/asir/thread_pool.rb', line 200 def join *args @run = false @thread.join(*args) if @thread end |
#kill!(*args) ⇒ Object
211 212 213 214 215 |
# File 'lib/asir/thread_pool.rb', line 211 def kill! *args stop! @thread.raise(*args) if @thread self end |
#run! ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/asir/thread_pool.rb', line 173 def run! @thread = Thread.current @run = @running = true while @run work = thread_pool.work_queue.deq if work == :stop! @run = false @stopping = true break end begin @work = work work.worker = self work.run! ensure work.thread = work.worker = nil @work = nil end end ensure if @stopping @stopped = true end @running = false @thread = nil end |
#stop! ⇒ Object
205 206 207 208 209 |
# File 'lib/asir/thread_pool.rb', line 205 def stop! @stopping = true @run = false self end |
#to_s ⇒ Object
170 |
# File 'lib/asir/thread_pool.rb', line 170 def to_s; super.sub(/>$/, " #{@worker_id} #{@work_inspect}>"); end |