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.
Here's one way: create a separate thread that loops infinitely and
does the sleeping and printing.
Kind regards
robert
2009/8/21 Hunt Jon <jona.hunt777@gmail.com>:
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.
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
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
On Fri, Aug 21, 2009 at 3:35 PM, Hunt Jon<jona.hunt777@gmail.com> 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.
--
A Look into Japanese Ruby List in English
Thanks. It woked fine. I just made the following:
Thread.new do
# code rhe
end