Class: Querrel::StaticPool

Inherits:
Object
  • Object
show all
Defined in:
lib/querrel/static_pool.rb

Instance Method Summary collapse

Constructor Details

#initialize(size) ⇒ StaticPool

Returns a new instance of StaticPool.



5
6
7
8
# File 'lib/querrel/static_pool.rb', line 5

def initialize(size)
  @size = size
  @jobs = Queue.new
end

Instance Method Details

#do_your_thang!Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/querrel/static_pool.rb', line 14

def do_your_thang!
  threads = Array.new(@size) do
    Thread.new do
      while job = @jobs.pop(true) rescue nil
        job.call
      end
    end
  end

  threads.each(&:join)
end

#enqueue(&job) ⇒ Object



10
11
12
# File 'lib/querrel/static_pool.rb', line 10

def enqueue(&job)
  @jobs.push(job)
end