I have a ruby script, which takes about 20 seconds to execute.
I want to show a dot (.) sign each second.
I think I need to use “sleep” method and a loop,
but I don’t know how to add the functionality to my script.
Any help would be appreciated.
I have a ruby script, which takes about 20 seconds to execute.
I want to show a dot (.) sign each second.
I think I need to use “sleep” method and a loop,
but I don’t know how to add the functionality to my script.
Any help would be appreciated.
On Fri, Aug 21, 2009 at 3:35 PM, Hunt J.[email protected] wrote:
I have a ruby script, which takes about 20 seconds to execute.
I want to show a dot (.) sign each second.
I think I need to use “sleep” method and a loop,
but I don’t know how to add the functionality to my script.Any help would be appreciated.
If you want to do that I think you would need a thread for that purpose.
Does your script now print nothing for that 20 seconds?
If so, you could print a dot after each step of your program finishes.
Then when you see the last dot, it will be finished, whether it took
19 seconds or 22 seconds, or whatever.
Just a suggestion.
(0…3_000_000).to_a #Fake busy time
print “.”
STDOUT.flush
(0…3_000_000).to_a #Next process, etc.
print “.”
STDOUT.flush
(0…3_000_000).to_a
print “.”
STDOUT.flush
(0…3_000_000).to_a
print “.”
STDOUT.flush
puts
Harry
2009/8/21 Hunt J. [email protected]:
I have a ruby script, which takes about 20 seconds to execute.
I want to show a dot (.) sign each second.
I think I need to use “sleep” method and a loop,
but I don’t know how to add the functionality to my script.Any help would be appreciated.
Here’s one way: create a separate thread that loops infinitely and
does the sleeping and printing.
Kind regards
robert
Thanks. It woked fine. I just made the following:
Thread.new do
end
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs