From: David Alan Black Date: 2001-08-08T11:39:41+09:00 Subject: [ruby-talk:19323] Re: timeout blocks Hello -- On Wed, 8 Aug 2001, Joseph McDonald wrote: > > Hi, > > I have a bit of a chicken and egg problem here. I want to use timeout > to initiate a socket connection, but have a timeout on the connection. > However if I use Timeout, the socket is out of scope by the time I > get connected. Can I somehow declare "s" as a socket above without > trying to connect? > > begin > timeout(5) do > s = TCPSocket.new(host, port) > end > rescue TimeoutError > puts "failed initial connect, retrying..." > retry > rescue > puts "failed #{$!}... retrying" > retry > end > # s is no longer available here. Wouldn't it work just to say: s = nil before the block? David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav