Is there a non-blocking version of io.eof?
- how to read until eof? (and than do other things)
···
______________________________________________
ruby-talk mailing list -- ruby-talk@ml.ruby-lang.org
To unsubscribe send an email to ruby-talk-leave@ml.ruby-lang.org
ruby-talk info -- Info | ruby-talk@ml.ruby-lang.org - ml.ruby-lang.org
There is not a non-blocking version of IO#eof?. That method works by
attempting to read a byte and putting it back if successful, and it was
coded to always block, much like IO#read.
If you want to perform non-blocking reads until the end of the file is
reached, require in the io/nonblock extension and use IO#read_nonblock.
It's a bit more limited than IO#read, but it will return bytes if they're
available, raise an exception (EOFError) if the end of file was reached, or
raise an exception (IO::EAGAINWaitReadable) if the read would block because
there is currently no data available. See more details here:
read_nonblock (IO) - APIdock.
-Jeremy
···
On Wed, Feb 28, 2024 at 7:45 AM Information via ruby-talk < ruby-talk@ml.ruby-lang.org> wrote:
Is there a non-blocking version of io.eof?
- how to read until eof? (and than do other things)