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.
167 168 169 |
# File 'lib/asir/thread_pool.rb', line 167 def run @run end |
#running ⇒ Object
Returns the value of attribute running.
167 168 169 |
# File 'lib/asir/thread_pool.rb', line 167 def running @running end |
#stopped ⇒ Object
Returns the value of attribute stopped.
167 168 169 |
# File 'lib/asir/thread_pool.rb', line 167 def stopped @stopped end |
#stopping ⇒ Object
Returns the value of attribute stopping.
167 168 169 |
# File 'lib/asir/thread_pool.rb', line 167 def stopping @stopping end |
#thread ⇒ Object
Current Work and Thread.
166 167 168 |
# File 'lib/asir/thread_pool.rb', line 166 def thread @thread end |
#thread_pool ⇒ Object
Returns the value of attribute thread_pool.
164 165 166 |
# File 'lib/asir/thread_pool.rb', line 164 def thread_pool @thread_pool end |
#work ⇒ Object
Current Work and Thread.
166 167 168 |
# File 'lib/asir/thread_pool.rb', line 166 def work @work end |
#worker_id ⇒ Object
Returns the value of attribute worker_id.
164 165 166 |
# File 'lib/asir/thread_pool.rb', line 164 def worker_id @worker_id end |
Instance Method Details
#inspect ⇒ Object
170 |
# File 'lib/asir/thread_pool.rb', line 170 def inspect; to_s; end |
#join(*args) ⇒ Object
199 200 201 202 |
# File 'lib/asir/thread_pool.rb', line 199 def join *args @run = false @thread.join(*args) if @thread end |
#kill!(*args) ⇒ Object
210 211 212 213 214 |
# File 'lib/asir/thread_pool.rb', line 210 def kill! *args stop! @thread.raise(*args) if @thread self end |
#run! ⇒ Object
172 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 |
# File 'lib/asir/thread_pool.rb', line 172 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
204 205 206 207 208 |
# File 'lib/asir/thread_pool.rb', line 204 def stop! @stopping = true @run = false self end |
#to_s ⇒ Object
169 |
# File 'lib/asir/thread_pool.rb', line 169 def to_s; super.sub(/>$/, " #{@worker_id} #{@work_inspect}>"); end |