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
83 def initialize(interval)
84   @interval = interval
85   @callbacks = []
86 end

Public Instance methods

<<(callback)
[show source]
    # File lib/httpx/timers.rb
102 def <<(callback)
103   @callbacks << callback
104 end
<=>(other)
[show source]
   # File lib/httpx/timers.rb
88 def <=>(other)
89   @interval <=> other.interval
90 end
==(other)
[show source]
   # File lib/httpx/timers.rb
92 def ==(other)
93   return @interval == other if other.is_a?(Numeric)
94 
95   @interval == other.to_f # rubocop:disable Lint/FloatComparison
96 end
delete(callback)
[show source]
    # File lib/httpx/timers.rb
106 def delete(callback)
107   @callbacks.delete(callback)
108 end
elapse(elapsed)
[show source]
    # File lib/httpx/timers.rb
118 def elapse(elapsed)
119   # same as elapsing
120   return 0 if @callbacks.empty?
121 
122   @interval -= elapsed
123 
124   if @interval <= 0
125     cb = @callbacks.dup
126     cb.each(&:call)
127   end
128 
129   @interval
130 end
elapsed?(elapsed = 0)
[show source]
    # File lib/httpx/timers.rb
114 def elapsed?(elapsed = 0)
115   (@interval - elapsed) <= 0 || @callbacks.empty?
116 end
no_callbacks?()
[show source]
    # File lib/httpx/timers.rb
110 def no_callbacks?
111   @callbacks.empty?
112 end
to_f()
[show source]
    # File lib/httpx/timers.rb
 98 def to_f
 99   Float(@interval)
100 end