Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to produce delay in ruby

Tags:

ruby

How to produce delay in ruby?

I used sleep statement but it didn't give me what I want.

puts "amit"
sleep(10)
puts "scj"

I want it to first print amit, then a delay of 10 seconds, then print scj.

But in above case what happens is it will pause for 10 seconds and then it will print amit and scj together. I don't want that.

I hope you got what I want to say.

like image 553
Amit Singh Tomar Avatar asked Jun 21 '10 11:06

Amit Singh Tomar


1 Answers

Call $stdout.flush before the call to sleep. The output is probably buffered (although usually output is only line-buffered so puts, which produces a newline, should work without flushing, but apparently that's not true for your terminal).

like image 161
sepp2k Avatar answered Oct 04 '22 17:10

sepp2k