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. on_empty
  10. to_f

Included modules

  1. Comparable

Attributes

interval [R]

Public Class methods

new(interval)
[show source]
   # File lib/httpx/timers.rb
56 def initialize(interval)
57   @interval = interval
58   @callbacks = []
59   @on_empty = nil
60 end

Public Instance methods

<<(callback)
[show source]
   # File lib/httpx/timers.rb
80 def <<(callback)
81   @callbacks << callback
82 end
<=>(other)
[show source]
   # File lib/httpx/timers.rb
66 def <=>(other)
67   @interval <=> other.interval
68 end
==(other)
[show source]
   # File lib/httpx/timers.rb
70 def ==(other)
71   return @interval == other if other.is_a?(Numeric)
72 
73   @interval == other.to_f # rubocop:disable Lint/FloatComparison
74 end
delete(callback)
[show source]
   # File lib/httpx/timers.rb
84 def delete(callback)
85   @callbacks.delete(callback)
86   @on_empty.call if @callbacks.empty?
87 end
elapse(elapsed)
[show source]
    # File lib/httpx/timers.rb
 97 def elapse(elapsed)
 98   @interval -= elapsed
 99 
100   if @interval <= 0
101     cb = @callbacks.dup
102     cb.each(&:call)
103   end
104 
105   @interval
106 end
elapsed?()
[show source]
   # File lib/httpx/timers.rb
93 def elapsed?
94   @interval <= 0
95 end
no_callbacks?()
[show source]
   # File lib/httpx/timers.rb
89 def no_callbacks?
90   @callbacks.empty?
91 end
on_empty(&blk)
[show source]
   # File lib/httpx/timers.rb
62 def on_empty(&blk)
63   @on_empty = blk
64 end
to_f()
[show source]
   # File lib/httpx/timers.rb
76 def to_f
77   Float(@interval)
78 end