Skip to content

Instantly share code, notes, and snippets.

@christiankakesa
Created October 24, 2018 02:52
Show Gist options
  • Save christiankakesa/247218128b63d21830528c9b93c46955 to your computer and use it in GitHub Desktop.
Save christiankakesa/247218128b63d21830528c9b93c46955 to your computer and use it in GitHub Desktop.
Example of simple ticker
struct Ticker
getter tick
@tick = Channel(Bool).new
def initialize(tick_s : Int32)
spawn do
loop do
sleep tick_s
@tick.send true
end
end
end
end
ticker = Ticker.new(2) # 2 seconds
spawn do
loop do
select
when ticker.tick.receive
puts "#{Time.now}"
end
end
end
sleep 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment