Class: ASIR::ThreadPool::Worker

Inherits:
Object
  • Object
show all
Includes:
AdditionalData, Initialization
Defined in:
lib/asir/thread_pool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Initialization

#initialize

Methods included from AdditionalData

#[], #[]=, #_additional_data, #additional_data, #additional_data!, #additional_data=, included

Instance Attribute Details

#runObject

Returns the value of attribute run.



167
168
169
# File 'lib/asir/thread_pool.rb', line 167

def run
  @run
end

#runningObject

Returns the value of attribute running.



167
168
169
# File 'lib/asir/thread_pool.rb', line 167

def running
  @running
end

#stoppedObject

Returns the value of attribute stopped.



167
168
169
# File 'lib/asir/thread_pool.rb', line 167

def stopped
  @stopped
end

#stoppingObject

Returns the value of attribute stopping.



167
168
169
# File 'lib/asir/thread_pool.rb', line 167

def stopping
  @stopping
end

#threadObject

Current Work and Thread.



166
167
168
# File 'lib/asir/thread_pool.rb', line 166

def thread
  @thread
end

#thread_poolObject

Returns the value of attribute thread_pool.



164
165
166
# File 'lib/asir/thread_pool.rb', line 164

def thread_pool
  @thread_pool
end

#workObject

Current Work and Thread.



166
167
168
# File 'lib/asir/thread_pool.rb', line 166

def work
  @work
end

#worker_idObject

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

#inspectObject



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_sObject



169
# File 'lib/asir/thread_pool.rb', line 169

def to_s; super.sub(/>$/, " #{@worker_id} #{@work_inspect}>"); end