Skip to content

Clarify documentation around close, flush, and isopen #58020

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jakobnissen
Copy link
Member

The previous documentation was unclear about what "closing" something actually meant, what you could expect from a closed resource, and whether it was usable in generic code.
It also mixed up closing IO object, timers and events, where the semantics are different.

In this commit:

  • The docstring of close and flush has been expanded.
  • close has been given a generic implementation
  • The documentation details specific to IOStream, Timer and Asyncevent has been moved to specific docstrings, such that the generic behaviour of these functions aren't mixed up with the specifics of e.g. IOStream.

Closes #57944

The previous documentation was unclear about what "closing" something actually
meant, what you could expect from a closed resource, and whether it was usable
in generic code.
It also mixed up closing IO object, timers and events, where the semantics are
different.

In this commit:
* The docstring of `close` and `flush` has been expanded.
* `close` has been given a generic implementation
* The documentation details specific to `IOStream`, `Timer` and `Asyncevent`
  has been moved to specific docstrings, such that the *generic* behaviour of
  these functions aren't mixed up with the specifics of e.g. `IOStream`.
@jakobnissen jakobnissen added io Involving the I/O subsystem: libuv, read, write, etc. docs This change adds or pertains to documentation labels Apr 6, 2025
@@ -9,7 +9,8 @@ Create a async condition that wakes up tasks waiting for it
(by calling [`wait`](@ref) on the object)
when notified from C by a call to `uv_async_send`.
Waiting tasks are woken with an error when the object is closed (by [`close`](@ref)).
Use [`isopen`](@ref) to check whether it is still active.
Use [`isopen`](@ref) to check whether it is still active. A closed condition will
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this would be better? Yes, the function is called isopen but the text says "active", not "open?

Suggested change
Use [`isopen`](@ref) to check whether it is still active. A closed condition will
Use [`isopen`](@ref) to check whether it is still active. An inactive condition will

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I see elsewhere the text already talks about "closed". I find this use of two different terms meaning the same thing adds a layer of potential confusion. So perhaps like this:

Suggested change
Use [`isopen`](@ref) to check whether it is still active. A closed condition will
Use [`isopen`](@ref) to check whether it is still active. A closed condition is inactive and will

@@ -74,7 +75,8 @@ Create a timer that wakes up tasks waiting for it (by calling [`wait`](@ref) on
Waiting tasks are woken after an initial delay of at least `delay` seconds, and then repeating after
at least `interval` seconds again elapse. If `interval` is equal to `0`, the timer is only triggered
once. When the timer is closed (by [`close`](@ref)) waiting tasks are woken with an error. Use
[`isopen`](@ref) to check whether a timer is still active. Use `t.timeout` and `t.interval` to read
[`isopen`](@ref) to check whether a timer is still active. A closed timer will not fire.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[`isopen`](@ref) to check whether a timer is still active. A closed timer will not fire.
[`isopen`](@ref) to check whether a timer is still active. An inactive timer will not fire.

"""
close(t::Union{Timer, AsyncCondition})

Close an object `t`. Once a timer or condition is closed, it will not produce
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continuing from above, how about

Suggested change
Close an object `t`. Once a timer or condition is closed, it will not produce
Close an object `t` and thus mark it as inactive. Once a timer or condition is inactive, it will not produce

However, since a closed stream may still have data to read in its buffer,
use [`eof`](@ref) to check for the ability to read data.
Use the `FileWatching` package to be notified when a stream might be writable or readable.
Determine whether an object, such as an IO or timer, is not yet closed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Determine whether an object, such as an IO or timer, is not yet closed.
Determine whether an object, such as an IO or timer, is still open and hence active.


Close an I/O stream. Performs a [`flush`](@ref) first.
This function is generically defined to only `flush` the io. That allows
wrapping IOs to close its underlying IO.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wrapping IOs to close its underlying IO.
wrapping IOs to close their underlying IOs.

Comment on lines +81 to +84
function close(io::IO)
flush(io)
nothing
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a change in behavior and thus goes beyond what the title of this PR suggests? I feel a bit uncomfortable with this -- I'd immediately agree to merge the docstring changes, but I don't feel qualified to judge whether this change is OK.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. The rest seems good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation io Involving the I/O subsystem: libuv, read, write, etc. status: waiting for author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

close is underdocumented, and inconsistently implemented
3 participants