0

I have coded something in ruby. Now, I want to make it so that every 3 seconds that code runs again. I have looked at threading. I built a thread and I put a

while true do end

loop inside it. Also I make it sleep for 3 seconds. Take a look

Thread.new do 
while true do
#code 
end
sleep 3
end

My problem is that when I run my code it doesn't run it at all and it doesn't repeat. Thank you

Bula
  • 2,398
  • 5
  • 28
  • 54

1 Answers1

0

Here's how to do it:

Thread.new do
  loop do 
    sleep 3000
    # your code here
  end
end

Courtesy of this post.

Community
  • 1
  • 1
knrz
  • 1,801
  • 1
  • 12
  • 15