Skip to content

Instantly share code, notes, and snippets.

@cpfarher
Created March 25, 2015 20:36
Show Gist options
  • Select an option

  • Save cpfarher/9bc88feb0bbb8451abae to your computer and use it in GitHub Desktop.

Select an option

Save cpfarher/9bc88feb0bbb8451abae to your computer and use it in GitHub Desktop.
require 'timers'
timers_scan = Timers::Group.new
scan=[3.0]
scan_started=[]
sleep_time=4.0
last_time=Time.now.to_f
loop {
scan.each do |v|
#if timers_scan.all? { |timer| timer.interval!=v }
if !scan_started.include? v
scan_started<<v
timers_scan.every(v) do
sleep(sleep_time)
puts "SCAN #{v} segundos - #{Time.now.to_f-last_time} -- #{sleep_time} s.".red
sleep_time=sleep_time-0.5 unless sleep_time==0
last_time=Time.now.to_f
end
end
end
timers_scan.wait
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment