class HTTPX::Timers::Interval

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

Methods

Public Class

  1. new

Public Instance

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

Included modules

  1. Comparable

Attributes

interval [R]

Public Class methods

new(interval)
[show source]
   # File lib/httpx/timers.rb
67 def initialize(interval)
68   @interval = interval
69   @callbacks = []
70   @on_empty = nil
71 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
cancel()
[show source]
   # File lib/httpx/timers.rb
77 def cancel
78   @on_empty.call
79 end
delete(callback)
[show source]
    # File lib/httpx/timers.rb
 99 def delete(callback)
100   @callbacks.delete(callback)
101   @on_empty.call if @callbacks.empty?
102 end
elapse(elapsed)
[show source]
    # File lib/httpx/timers.rb
112 def elapse(elapsed)
113   @interval -= elapsed
114 
115   if @interval <= 0
116     cb = @callbacks.dup
117     cb.each(&:call)
118   end
119 
120   @interval
121 end
elapsed?()
[show source]
    # File lib/httpx/timers.rb
108 def elapsed?
109   @interval <= 0
110 end
no_callbacks?()
[show source]
    # File lib/httpx/timers.rb
104 def no_callbacks?
105   @callbacks.empty?
106 end
on_empty(&blk)
[show source]
   # File lib/httpx/timers.rb
73 def on_empty(&blk)
74   @on_empty = blk
75 end
to_f()
[show source]
   # File lib/httpx/timers.rb
91 def to_f
92   Float(@interval)
93 end