class ConnectionPool::TimedStack

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/connection_pool/timed_stack.rbs

class ConnectionPool::TimedStack
  def connection_stored?: (?Hash options) -> untyped
  def current_time: () -> untyped
  def fetch_connection: (?Hash options) -> untyped
  def pop: (?Integer timeout, ?Hash options) -> untyped
  def push: (Sidekiq::RedisClientAdapter::CompatClient obj, ?Hash options) -> untyped
  def store_connection: (Sidekiq::RedisClientAdapter::CompatClient obj, ?Hash options) -> untyped
end

def connection_stored?(options = nil)

Experimental RBS support (using type sampling data from the type_fusion project).

def connection_stored?: (? options) -> untyped

This signature was generated using 4 samples from 1 application.

def connection_stored?(options = nil)
  !@que.empty?
end

def current_time

Experimental RBS support (using type sampling data from the type_fusion project).

def current_time: () -> untyped

This signature was generated using 1 sample from 1 application.

def current_time
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
end

def empty?

def empty?
  (@created - @que.length) >= @max
end

def fetch_connection(options = nil)

Experimental RBS support (using type sampling data from the type_fusion project).

def fetch_connection: (? options) -> untyped

This signature was generated using 1 sample from 1 application.

def fetch_connection(options = nil)
  @que.pop
end

def initialize(size = 0, &block)

def initialize(size = 0, &block)
  @create_block = block
  @created = 0
  @que = []
  @max = size
  @mutex = Thread::Mutex.new
  @resource = Thread::ConditionVariable.new
  @shutdown_block = nil
end

def length

def length
  @max - @created + @que.length
end

def pop(timeout = 0.5, options = {})

Experimental RBS support (using type sampling data from the type_fusion project).

def pop: (?Integer timeout, ? options) -> untyped

This signature was generated using 4 samples from 1 application.

def pop(timeout = 0.5, options = {})
  options, timeout = timeout, 0.5 if Hash === timeout
  timeout = options.fetch :timeout, timeout
  deadline = current_time + timeout
  @mutex.synchronize do
    loop do
      raise ConnectionPool::PoolShuttingDownError if @shutdown_block
      return fetch_connection(options) if connection_stored?(options)
      connection = try_create(options)
      return connection if connection
      to_wait = deadline - current_time
      raise ConnectionPool::TimeoutError, "Waited #{timeout} sec, #{length}/#{@max} available" if to_wait <= 0
      @resource.wait(@mutex, to_wait)
    end
  end
end

def push(obj, options = {})

Experimental RBS support (using type sampling data from the type_fusion project).

def push: (Sidekiq::RedisClientAdapter::CompatClient obj, ? options) -> untyped

This signature was generated using 1 sample from 1 application.

def push(obj, options = {})
  @mutex.synchronize do
    if @shutdown_block
      @shutdown_block.call(obj)
    else
      store_connection obj, options
    end
    @resource.broadcast
  end
end

def shutdown(reload: false, &block)

def shutdown(reload: false, &block)
  raise ArgumentError, "shutdown must receive a block" unless block
  @mutex.synchronize do
    @shutdown_block = block
    @resource.broadcast
    shutdown_connections
    @shutdown_block = nil if reload
  end
end

def shutdown_connections(options = nil)

def shutdown_connections(options = nil)
  while connection_stored?(options)
    conn = fetch_connection(options)
    @shutdown_block.call(conn)
  end
  @created = 0
end

def store_connection(obj, options = nil)

Experimental RBS support (using type sampling data from the type_fusion project).

def store_connection: (Sidekiq::RedisClientAdapter::CompatClient obj, ? options) -> untyped

This signature was generated using 1 sample from 1 application.

def store_connection(obj, options = nil)
  @que.push obj
end

def try_create(options = nil)

def try_create(options = nil)
  unless @created == @max
    object = @create_block.call
    @created += 1
    object
  end
end