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

Public Instance methods

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