class Lifeguard::InfiniteThreadpool

Public Class Methods

new(opts = {}) click to toggle source
Calls superclass method Lifeguard::Threadpool::new
# File lib/lifeguard/infinite_threadpool.rb, line 7
def initialize(opts = {})
  super(opts)
  @shutdown = false
  @super_async_mutex = ::Mutex.new
end

Public Instance Methods

async(*args, &block) click to toggle source
Calls superclass method Lifeguard::Threadpool#async
# File lib/lifeguard/infinite_threadpool.rb, line 13
def async(*args, &block)
  return false if @shutdown

  if busy?
    job_mutex = ::Mutex.new
    job_condition = ::ConditionVariable.new
    # Account for "weird" exceptions like Java Exceptions or higher up the chain
    # than what `rescue nil` will capture
    job_mutex.synchronize do
      new_thread = ::Thread.new(block, args) do |callable, call_args|
        job_mutex.synchronize do
          begin
            ::Thread.current[:__start_time_in_seconds__] = Time.now.to_i
            ::Thread.current.abort_on_exception = false

            callable.call(*call_args)
          ensure
            job_condition.signal
          end
        end
      end

      job_condition.wait(job_mutex)
    end
  else
    super(*args, &block)
  end

  return true
end
kill!(*args) click to toggle source
Calls superclass method Lifeguard::Threadpool#kill!
# File lib/lifeguard/infinite_threadpool.rb, line 44
def kill!(*args)
  super
  @shutdown = true
end
shutdown(*args) click to toggle source
Calls superclass method Lifeguard::Threadpool#shutdown
# File lib/lifeguard/infinite_threadpool.rb, line 49
def shutdown(*args)
  @shutdown = true
  super
end