Class: Net::HTTP::Persistent::TimedStackMulti

Inherits:
ConnectionPool::TimedStack
  • Object
show all
Defined in:
lib/net/http/persistent/timed_stack_multi.rb

Overview

:nodoc:

Constant Summary collapse

CP_USES_KEYWORD_ARGS =

Detects if ConnectionPool 3.0+ is being used (needed for TimedStack subclass compatibility)

Gem::Version.new(ConnectionPool::VERSION) >= Gem::Version.new('3.0.0')

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size = 0, &block) ⇒ TimedStackMulti

Returns a new instance of TimedStackMulti.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/net/http/persistent/timed_stack_multi.rb', line 18

def initialize(size = 0, &block)
  if CP_USES_KEYWORD_ARGS
    super(size: size, &block)
  else
    super(size, &block)
  end

  @enqueued = 0
  @ques = self.class.hash_of_arrays
  @lru = {}
  @key = :"connection_args-#{object_id}"
end

Class Method Details

.hash_of_arraysObject

Returns a new hash that has arrays for keys

Using a class method to limit the bindings referenced by the hash’s default_proc



14
15
16
# File 'lib/net/http/persistent/timed_stack_multi.rb', line 14

def self.hash_of_arrays # :nodoc:
  Hash.new { |h,k| h[k] = [] }
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/net/http/persistent/timed_stack_multi.rb', line 31

def empty?
  (@created - @enqueued) >= @max
end

#lengthObject



35
36
37
# File 'lib/net/http/persistent/timed_stack_multi.rb', line 35

def length
  @max - @created + @enqueued
end