Methods
Public Class
Public Instance
Included modules
- 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