I'm trying to create an infinite loop, where a block of code will be executed forever.
All loop documentation I have found warns against creating an infinite loop, but no examples of a working one.
If I have a block of code:
{ puts "foo"
puts "bar"
sleep 300 }
How would I go about running this block forever?
ruby-on-rails
. If you're trying to create an infinite loop in Rails, you're probably doing something horribly wrong. You can't do that in the same process that is serving your site, or the single thread of execution cannot actually respond to incoming requests. If you want to do something every 300 seconds, you need an asynchronous background job. You should describe your actual problem so we can provide you with real advice - using an infinite loop is a solution, not a problem.