Class: RbbtThreadQueue::RbbtThreadQueueWorker

Inherits:
Thread
  • Object
show all
Defined in:
lib/rbbt/util/concurrency/threads.rb

Instance Method Summary collapse

Constructor Details

#initialize(queue, mutex = nil, &block) ⇒ RbbtThreadQueueWorker

Returns a new instance of RbbtThreadQueueWorker.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rbbt/util/concurrency/threads.rb', line 5

def initialize(queue, mutex = nil, &block)
  if mutex.nil?
    super(Thread.current) do |parent|
      begin
        loop do
          p = queue.pop
          block.call *p
        end
      rescue Exception
        raise $!
      end
    end
  else
    super(Thread.current) do |parent|
      begin
        loop do
          p = queue.pop
          p = Array === p ? p << mutex : [p,mutex]
          block.call *p
        end
      rescue Exception
        raise $!
      end
    end
  end
end

Instance Method Details

#cleanObject

Raises:



32
33
34
# File 'lib/rbbt/util/concurrency/threads.rb', line 32

def clean
  raise Aborted if alive?
end