class Chrono::Trigger

Attributes

block[R]
source[R]

Public Class Methods

new(source, &block) click to toggle source
# File lib/chrono/trigger.rb, line 5
def initialize(source, &block)
  @source = source
  @block = block || -> {}
end

Public Instance Methods

once() click to toggle source
# File lib/chrono/trigger.rb, line 10
def once
  wait
  call
end
run() click to toggle source
# File lib/chrono/trigger.rb, line 15
def run
  loop { once }
end

Private Instance Methods

call() click to toggle source
# File lib/chrono/trigger.rb, line 21
def call
  block.call
end
iterator() click to toggle source
# File lib/chrono/trigger.rb, line 25
def iterator
  @iterator ||= Iterator.new(source)
end
period() click to toggle source
# File lib/chrono/trigger.rb, line 33
def period
  iterator.next - Time.now + 1.second
end
wait() click to toggle source
# File lib/chrono/trigger.rb, line 29
def wait
  sleep(period)
end