I have a Ruby script that looks like:
def big_function
puts "starting..."
#does stuff
puts "done"
end
loop do
big_function
end
It runs indefinitely, executing big_function.
I need a way for a user to interrupt the running script but never in the middle of big_function. If it is interrupted while big_function is running, it should exit when big_function is done.
You could use flags. You can have a separate process polling in the key triggering of the user, and if he clicks or press a key that flag changes state. You will have to check the flag before exiting.