class HTTPX::Timers::Interval

  1. lib/httpx/timers.rb
Superclass: Object

Methods

Public Class

  1. new

Public Instance

  1. <<
  2. <=>
  3. ==
  4. delete
  5. elapse
  6. elapsed?
  7. interval
  8. no_callbacks?
  9. to_f

Included modules

  1. Comparable

Attributes

interval [R]

Public Class methods

new(interval)
[show source]
   # File lib/httpx/timers.rb
80 def initialize(interval)
81   @interval = interval
82   @callbacks = []
83 end

Public Instance methods

<<(callback)
[show source]
    # File lib/httpx/timers.rb
 99 def <<(callback)
100   @callbacks << callback
101 end
<=>(other)
[show source]
   # File lib/httpx/timers.rb
85 def <=>(other)
86   @interval <=> other.interval
87 end
==(other)
[show source]
   # File lib/httpx/timers.rb
89 def ==(other)
90   return @interval == other if other.is_a?(Numeric)
91 
92   @interval == other.to_f # rubocop:disable Lint/FloatComparison
93 end
delete(callback)
[show source]
    # File lib/httpx/timers.rb
103 def delete(callback)
104   @callbacks.delete(callback)
105 end
elapse(elapsed)
[show source]
    # File lib/httpx/timers.rb
115 def elapse(elapsed)
116   # same as elapsing
117   return 0 if @callbacks.empty?
118 
119   @interval -= elapsed
120 
121   if @interval <= 0
122     cb = @callbacks.dup
123     cb.each(&:call)
124   end
125 
126   @interval
127 end
elapsed?(elapsed = 0)
[show source]
    # File lib/httpx/timers.rb
111 def elapsed?(elapsed = 0)
112   (@interval - elapsed) <= 0 || @callbacks.empty?
113 end
no_callbacks?()
[show source]
    # File lib/httpx/timers.rb
107 def no_callbacks?
108   @callbacks.empty?
109 end
to_f()
[show source]
   # File lib/httpx/timers.rb
95 def to_f
96   Float(@interval)
97 end