-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
base: master
Are you sure you want to change the base?
Conversation
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`.
@@ -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 |
There was a problem hiding this comment.
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?
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 |
There was a problem hiding this comment.
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:
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[`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 |
There was a problem hiding this comment.
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
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrapping IOs to close its underlying IO. | |
wrapping IOs to close their underlying IOs. |
function close(io::IO) | ||
flush(io) | ||
nothing | ||
end |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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:
close
andflush
has been expanded.close
has been given a generic implementationIOStream
,Timer
andAsyncevent
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