Class: ThreadStorm::Worker

Inherits:
Object show all
Defined in:
lib/thread_storm/worker.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue) ⇒ Worker

Returns a new instance of Worker.



5
6
7
8
# File 'lib/thread_storm/worker.rb', line 5

def initialize(queue)
  @queue     = queue
  @thread    = Thread.new(self){ |me| me.run }
end

Instance Attribute Details

#threadObject (readonly)

Returns the value of attribute thread.



3
4
5
# File 'lib/thread_storm/worker.rb', line 3

def thread
  @thread
end

Instance Method Details

#runObject

Pop executions and process them until we’re signaled to die.



11
12
13
14
15
16
# File 'lib/thread_storm/worker.rb', line 11

def run
  while (execution = @queue.dequeue)
    execution.execute
    @queue.decr_size
  end
end