[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

sleep not adding up

jabowen

1/22/2008 4:35:00 AM

I was hoping that the following code would print out hi with one second
gaps. However it waits 5 seconds and then prints out hi 5 times.


def test_puts
puts 'hi'
end

def test_sleep
sleep 1
test_puts
end

5.downto(1) do
test_sleep
end
--
Posted via http://www.ruby-....

2 Answers

Daniel Sheppard

1/22/2008 4:57:00 AM

0

> def test_puts
> puts 'hi'
STDOUT.flush
> end
>=20
> def test_sleep
> sleep 1
> test_puts
> end
>=20
> 5.downto(1) do
> test_sleep
> end

On windows, you need to manually flush STDOUT/STDERR if you want to see
the output prior to the program ending.

Dan.

Clifford Heath

1/22/2008 6:51:00 AM

0

Daniel Sheppard wrote:
> On windows, you need to manually flush STDOUT/STDERR if you want to see
> the output prior to the program ending.

Yes - or read some input from $stdin. A difference in the C library
settings which might depend on which type of build you're using.

Clifford Heath.