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.
165 166 167 |
# File 'lib/asir/thread_pool.rb', line 165 def run @run end |
#running ⇒ Object
Returns the value of attribute running.
165 166 167 |
# File 'lib/asir/thread_pool.rb', line 165 def running @running end |
#stopped ⇒ Object
Returns the value of attribute stopped.
165 166 167 |
# File 'lib/asir/thread_pool.rb', line 165 def stopped @stopped end |
#stopping ⇒ Object
Returns the value of attribute stopping.
165 166 167 |
# File 'lib/asir/thread_pool.rb', line 165 def stopping @stopping end |
#thread ⇒ Object
Current Work and Thread.
164 165 166 |
# File 'lib/asir/thread_pool.rb', line 164 def thread @thread end |
#thread_pool ⇒ Object
Returns the value of attribute thread_pool.
162 163 164 |
# File 'lib/asir/thread_pool.rb', line 162 def thread_pool @thread_pool end |
#work ⇒ Object
Current Work and Thread.
164 165 166 |
# File 'lib/asir/thread_pool.rb', line 164 def work @work end |
#worker_id ⇒ Object
Returns the value of attribute worker_id.
162 163 164 |
# File 'lib/asir/thread_pool.rb', line 162 def worker_id @worker_id end |
Instance Method Details
#inspect ⇒ Object
168 |
# File 'lib/asir/thread_pool.rb', line 168 def inspect; to_s; end |
#join(*args) ⇒ Object
197 198 199 200 |
# File 'lib/asir/thread_pool.rb', line 197 def join *args @run = false @thread.join(*args) if @thread end |
#kill!(*args) ⇒ Object
208 209 210 211 212 |
# File 'lib/asir/thread_pool.rb', line 208 def kill! *args stop! @thread.raise(*args) if @thread self end |
#run! ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/asir/thread_pool.rb', line 170 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
202 203 204 205 206 |
# File 'lib/asir/thread_pool.rb', line 202 def stop! @stopping = true @run = false self end |
#to_s ⇒ Object
167 |
# File 'lib/asir/thread_pool.rb', line 167 def to_s; super.sub(/>$/, " #{@worker_id} #{@work_inspect}>"); end |