Class: Sideband::Thread

Inherits:
Object
  • Object
show all
Defined in:
lib/sideband/thread.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manager) ⇒ Thread

Returns a new instance of Thread.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/sideband/thread.rb', line 6

def initialize(manager)
  @manager = manager
  @thread = ::Thread.new do
    while @manager.queue && work = @manager.queue.pop
      exit if work.nil?
      
      begin
        work.call
      rescue Exception
        # Sideband will ignore all Exceptions, 
        # better to handle in your workers.
      end
    end
  end
end

Instance Attribute Details

#threadObject (readonly)

Returns the value of attribute thread.



4
5
6
# File 'lib/sideband/thread.rb', line 4

def thread
  @thread
end

Instance Method Details

#joinObject



22
23
24
# File 'lib/sideband/thread.rb', line 22

def join
  thread.join
end

#killObject



26
27
28
# File 'lib/sideband/thread.rb', line 26

def kill
  thread.kill
end