ruby - Perform a loop for a certain time interval or while condition is met -
i trying have check fire off every second 30 seconds. haven't found clear way ruby yet. trying currently:
until counter == 30 sleep 1 if condition break else counter +=1 end
problem has use sleep, stops thread in tracks full second. there way achieve similar above without use of sleep? there way have cycle though on time based interval?
you can approximate you're looking along these lines:
now = time.now counter = 1 loop if time.now < + counter next else puts "counting second ..." end counter += 1 break if counter > 30 end
Comments
Post a Comment