class AVR::Clock
Attributes
count[RW]
name[R]
scale[RW]
sinks[R]
ticks[RW]
watches[R]
Public Class Methods
new(name = nil)
click to toggle source
# File lib/avr/clock.rb, line 52 def initialize(name = nil) @name = name @sinks = T.let([], T::Array[Sink]) @watches = T.let({}, T::Hash[Integer, T.untyped]) @ticks = T.let(0, Integer) @count = T.let(0, Integer) @scale = T.let(1, Integer) @last_tick = T.let(0, Integer) end
Public Instance Methods
clear_sinks()
click to toggle source
# File lib/avr/clock.rb, line 73 def clear_sinks @sinks = [] end
notify_at_tick(tick, sink)
click to toggle source
# File lib/avr/clock.rb, line 78 def notify_at_tick(tick, sink) @watches[tick] ||= [] @watches[tick] << sink end
push_sink(sink)
click to toggle source
# File lib/avr/clock.rb, line 68 def push_sink(sink) sinks.push(sink) end
tick(_source = nil, _ticks = nil)
click to toggle source
# File lib/avr/clock.rb, line 84 def tick(_source = nil, _ticks = nil) @count += 1 if (@count % @scale).zero? @last_tick = @ticks sinks.each do |sink| sink.tick(self, @ticks) end watches[@ticks]&.each do |watch| watch.tick(self, @ticks) end @ticks += 1 end @last_tick end
unshift_sink(sink)
click to toggle source
# File lib/avr/clock.rb, line 63 def unshift_sink(sink) sinks.unshift(sink) end