[plt-scheme] timeout for read-line

From: Vincent Hourdin (vinvinhc16 at ifrance.com)
Date: Wed Feb 4 16:59:24 EST 2004

On Tuesday 03 February 2004 16:57, ifconfig wrote:
> Here's a way to do it:
> (there's probably a much easier way I don't know about though. This
> hasn't been tested but should work).
>
> (define (read-line-with-timeout timeout)
>   (with-handlers ([exn:user? (lambda (e) #f)])
> 		; this returns #f on break or timeout.
>     (let ([breaker (lambda (thread-to-break)
>                      (sleep timeout)
>                      (break thread-to-break))]
> 		; not sure this should be (break thread). If doesn't
> work, check 		; the help files for breaking threads.
>           [break-thread (thread (lambda () (breaker (current-thread))))]
>           [result (read-line)])
>       (kill-thread break-thread)
> 		; this is so it doesn't break after reading.
>       result)))

I was waiting for something more... "built-in feature" or lighter. It will be 
done at each loop, and often, it wont even be necessary to wait.
Any suggestions ?





Posted on the users mailing list.