Methods
Public Class
Public Instance
Included modules
- Comparable
Attributes
| interval | [R] |
Public Class methods
new(interval)
[show source]
# File lib/httpx/timers.rb 80 def initialize(interval) 81 @interval = interval 82 @callbacks = [] 83 end
Public Instance methods
<<(callback)
[show source]
# File lib/httpx/timers.rb 99 def <<(callback) 100 @callbacks << callback 101 end
<=>(other)
[show source]
# File lib/httpx/timers.rb 85 def <=>(other) 86 @interval <=> other.interval 87 end
==(other)
[show source]
# File lib/httpx/timers.rb 89 def ==(other) 90 return @interval == other if other.is_a?(Numeric) 91 92 @interval == other.to_f # rubocop:disable Lint/FloatComparison 93 end
delete(callback)
[show source]
# File lib/httpx/timers.rb 103 def delete(callback) 104 @callbacks.delete(callback) 105 end
elapse(elapsed)
[show source]
# File lib/httpx/timers.rb 115 def elapse(elapsed) 116 # same as elapsing 117 return 0 if @callbacks.empty? 118 119 @interval -= elapsed 120 121 if @interval <= 0 122 cb = @callbacks.dup 123 cb.each(&:call) 124 end 125 126 @interval 127 end
elapsed?(elapsed = 0)
[show source]
# File lib/httpx/timers.rb 111 def elapsed?(elapsed = 0) 112 (@interval - elapsed) <= 0 || @callbacks.empty? 113 end
no_callbacks?()
[show source]
# File lib/httpx/timers.rb 107 def no_callbacks? 108 @callbacks.empty? 109 end