Class: Threaded::Worker

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

Constant Summary collapse

POISON =
"poison"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue, options = {}) ⇒ Worker

Returns a new instance of Worker.



6
7
8
9
10
# File 'lib/threaded/worker.rb', line 6

def initialize(queue, options = {})
  @queue   = queue
  @logger  = options[:logger]  || Threaded.logger
  @thread  = create_thread
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



4
5
6
# File 'lib/threaded/worker.rb', line 4

def logger
  @logger
end

#queueObject (readonly)

Returns the value of attribute queue.



4
5
6
# File 'lib/threaded/worker.rb', line 4

def queue
  @queue
end

#threadObject (readonly)

Returns the value of attribute thread.



4
5
6
# File 'lib/threaded/worker.rb', line 4

def thread
  @thread
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/threaded/worker.rb', line 24

def alive?
  thread.alive?
end

#dead?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/threaded/worker.rb', line 20

def dead?
  !alive?
end

#joinObject



28
29
30
# File 'lib/threaded/worker.rb', line 28

def join
  thread.join
end

#poisonObject



12
13
14
# File 'lib/threaded/worker.rb', line 12

def poison
  @queue.enq(POISON)
end

#startObject



16
17
18
# File 'lib/threaded/worker.rb', line 16

def start
  puts "start is deprecated, thread is started when worker created"
end