snipplets.dev/code/Crystal/schedule.cr

19 lines
219 B
Crystal
Raw Normal View History

2022-10-08 00:31:44 +03:00
def every(period : Time::Span, &block : -> T) forall T
spawn do
loop do
block.call
sleep period
end
end
end
every(2.seconds) {
puts "-@-@-"
}
every(4.seconds) {
puts "(-.-)Zzz..."
}
sleep