class Af::ThreadPool::Worker

Attributes

thread[R]

Public Class Methods

new(thread_class = Thread) click to toggle source
# File lib/fiksu-af/thread_pool.rb, line 11
def initialize(thread_class = Thread)
  @mutex = Mutex.new
  @thread = thread_class.new do
    while true
      sleep 0.001
      block = get_block
      if block
        block.call
        reset_block
      end
    end
  end
end

Public Instance Methods

busy?() click to toggle source
# File lib/fiksu-af/thread_pool.rb, line 40
def busy?
  @mutex.synchronize {!@block.nil?}
end
get_block() click to toggle source
# File lib/fiksu-af/thread_pool.rb, line 25
def get_block
  @mutex.synchronize {@block}
end
reset_block() click to toggle source
# File lib/fiksu-af/thread_pool.rb, line 36
def reset_block
  @mutex.synchronize {@block = nil}
end
set_block(block) click to toggle source
# File lib/fiksu-af/thread_pool.rb, line 29
def set_block(block)
  @mutex.synchronize do
    raise RuntimeError, "Thread already busy." if @block
    @block = block
  end
end