snipplets.dev/snipplets/code/Crystal/schedule.cr
2023-08-05 22:45:06 +03:00

19 lines
219 B
Crystal

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