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
76 def initialize(interval)
77   @interval = interval
78   @callbacks = []
79 end

Public Instance methods

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