Method: Workhorse::Pool#post

Defined in:
lib/workhorse/pool.rb

#postObject

Posts a new work unit to the pool.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/workhorse/pool.rb', line 25

def post
  mutex.synchronize do
    if idle.zero?
      fail 'All threads are busy.'
    end

    active_threads = @active_threads

    active_threads.increment

    @executor.post do
      begin
        yield
      ensure
        active_threads.decrement
        @on_idle.try(:call)
      end
    end
  end
end