Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should we breathe new life into readavailable? #57994

Open
jakobnissen opened this issue Apr 2, 2025 · 0 comments
Open

Should we breathe new life into readavailable? #57994

jakobnissen opened this issue Apr 2, 2025 · 0 comments
Labels
io Involving the I/O subsystem: libuv, read, write, etc.

Comments

@jakobnissen
Copy link
Member

jakobnissen commented Apr 2, 2025

The function readavailable is in an awkward position. The documentation says:

Read available buffered data from a stream. Actual I/O is performed only if no data has already been
buffered. The result is a Vector{UInt8}.

This makes it sound like it does the following:

  • If data is available in the internal buffer of the IO, read that
  • Else, do one blocking operation to fill the internal buffer and then return whatever you get

This reply implies that that's indeed what it does.
It's also what the default definition of write(::IO, ::IO) implies it does

However, in the docstring, the sentence is followed by the warning:

Warning

│ The amount of data returned is implementation-dependent; for example it can depend on the
│ internal choice of buffer size. Other functions such as read should generally be used
│ instead.

And the comments in #16821 also implies that this function should not be used at all.

But why? Isn't it quite useful to have a function that reads all the available data? To be sure, I'm a bit bummed out that readavailable doesn't actually read the available bytes, which you would really, really think it did from its name, but apparently also does a blocking operation if that number is zero.

I think it would be nice to either:

  • Clarify that readavailable will return all of the bytes given by bytesavailable if that is nonzero, or else do one blocking read, and will read what becomes available from that, and remove the warning from the docstring, or
  • Slightly change the meaning of readavailable to do what it says on the tin and read exactly the available bytes, no less, no more.

The latter would be nicer, but is slightly breaking and may be too breaking.
And maybe there's a reason for the warning?

@jakobnissen jakobnissen added the io Involving the I/O subsystem: libuv, read, write, etc. label Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
io Involving the I/O subsystem: libuv, read, write, etc.
Projects
None yet
Development

No branches or pull requests

1 participant