Class: Backport::Server::Interval
- Defined in:
- lib/backport/server/interval.rb
Overview
A Backport periodical interval server.
Instance Method Summary collapse
-
#initialize(period, &block) {|| ... } ⇒ Interval
constructor
A new instance of Interval.
- #starting ⇒ Object
- #tick ⇒ Object
Methods inherited from Base
#start, #started?, #stop, #stopped?, #stopping
Constructor Details
#initialize(period, &block) {|| ... } ⇒ Interval
Returns a new instance of Interval.
9 10 11 12 13 |
# File 'lib/backport/server/interval.rb', line 9 def initialize period, &block @period = period @block = block @last_time = Time.now end |
Instance Method Details
#starting ⇒ Object
15 16 17 |
# File 'lib/backport/server/interval.rb', line 15 def starting @last_time = Time.now end |
#tick ⇒ Object
19 20 21 22 23 24 |
# File 'lib/backport/server/interval.rb', line 19 def tick now = Time.now return unless now - @last_time >= @period @block.call self @last_time = now end |