From: David Vallner Date: 2006-11-12T05:10:59+09:00 Subject: Re: print message if user does nothing for x seconds? --------------enig3B870C71D6967C8A8EA3F190 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Ben Thomas wrote: > Hi all, >=20 > Only just started using ruby so this may be really simple to do, but > here goes: >=20 > I'm trying to write a program that asks a user to enter their sex using= > "gets" but if the user doesn't type anything for about 5 seconds I want= > to print a message, like "Please enter something..." then go back to th= e > gets prompt. I've tried using the "sleep x" method but it doesn't seem > to work because once gets has been initiated it gets stuck there until > something is entered. >=20 > Oh I don't have to use gets, but this is the only method of input I'm > aware of at the moment >=20 > Hope this makes sense, > Ben >=20 >=20 Read the data in a thread, or use nonblocking io (currently crude at best, with only eventmachine to help as a project that shown up on my radar - and that seems to be oriented towards networking) Also, what you describe there is a very rude thing to do to your user, basically you're accusing them of having no attention span and the program is attention-seeking to compensate. David Vallner --------------enig3B870C71D6967C8A8EA3F190 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (MingW32) iD8DBQFFVi5/y6MhrS8astoRAjKmAJ9nLzbsQR2Sr/im02Dp+G2d7YB48ACdHyOc 9+cdlFLtQ/6UxwtEGg+Bh/c= =/RCs -----END PGP SIGNATURE----- --------------enig3B870C71D6967C8A8EA3F190--