Class: Scruby::Scheduler

Inherits:
Ticker show all
Defined in:
lib/scruby/ticker.rb

Instance Attribute Summary

Attributes inherited from Ticker

#interval, #loop, #resolution, #size, #start, #tempo, #tick

Instance Method Summary collapse

Methods inherited from Ticker

#block, #index, #next_time, #run, #running?, #stop

Constructor Details

#initialize(opts = {}) ⇒ Scheduler

Returns a new instance of Scheduler.



75
76
77
78
# File 'lib/scruby/ticker.rb', line 75

def initialize opts = {}
  super
  @queue = []
end

Instance Method Details

#at(tick, &proc) ⇒ Object



86
87
88
89
# File 'lib/scruby/ticker.rb', line 86

def at tick, &proc
  @queue[tick] ||= []
  @queue[tick].push proc
end

#dispatchObject



80
81
82
83
84
# File 'lib/scruby/ticker.rb', line 80

def dispatch
  if blocks = @queue[index]
    blocks.each{ |b| b.call  }
  end
end