Class: ASIR::ThreadPool::Work

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

#block ⇒ Object

Returns the value of attribute block.



141
142
143
# File 'lib/asir/thread_pool.rb', line 141

def block
  @block
end

#finished ⇒ Object

Returns the value of attribute finished.



142
143
144
# File 'lib/asir/thread_pool.rb', line 142

def finished
  @finished
end

#started ⇒ Object

Returns the value of attribute started.



142
143
144
# File 'lib/asir/thread_pool.rb', line 142

def started
  @started
end

#thread ⇒ Object

Returns the value of attribute thread.



141
142
143
# File 'lib/asir/thread_pool.rb', line 141

def thread
  @thread
end

#work_id ⇒ Object

Returns the value of attribute work_id.



141
142
143
# File 'lib/asir/thread_pool.rb', line 141

def work_id
  @work_id
end

#worker ⇒ Object

Returns the value of attribute worker.



141
142
143
# File 'lib/asir/thread_pool.rb', line 141

def worker
  @worker
end

Instance Method Details

#inspect ⇒ Object



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

def inspect; to_s; end

#run! ⇒ Object



147
148
149
150
151
152
153
154
155
156
# File 'lib/asir/thread_pool.rb', line 147

def run!
  @thread = ::Thread.current
  thread_pool.work_starting! self
  @started = true
  @block.call
  @finished = true
ensure
  @thread = nil
  thread_pool.work_stopping! self
end

#thread_pool ⇒ Object



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

def thread_pool; @worker.thread_pool; end

#to_s ⇒ Object



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

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