You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When threading a context.Context down to code which uses a net.Conn directly, I wanted to write the following code:
deadline, _ := ctx.Deadline()
if err := conn.SetDeadline(deadline); err != nil {
// ...
}
// use conn
But because Context.Deadline does not document that deadline == time.Time{} when ok == false, I felt compelled to write this instead:
deadline, ok := ctx.Deadline()
if !ok {
deadline = time.Time{}
}
if err := conn.SetDeadline(deadline); err != nil {
// ...
}
// use conn
The current documentation says Deadline returns ok==false when no deadline is set, but does not mention anything about the value of deadline in that case.
Should it? Or is it self-evident on the basis that things which return (T, bool) generally return the zero value for T when the boolean is false?
I do realize that context.Context is an interface, but it would be nice to be able to rely on deadline == time.Time{} when the context has no associated deadline.
I propose changing the documentation to Deadline returns deadline == time.Time{} and ok == false when no deadline is set for clarification. If this is acceptable, I can send a CL.
The text was updated successfully, but these errors were encountered:
Deadline returns ok==false when no deadline is set should be enough. It wouldn't be expected that the value of deadline is anything meaningful or useful should ok be false, so that shouldn't require any additional documentation.
When threading a
context.Context
down to code which uses anet.Conn
directly, I wanted to write the following code:But because
Context.Deadline
does not document thatdeadline == time.Time{}
whenok == false
, I felt compelled to write this instead:The current documentation says
Deadline returns ok==false when no deadline is set
, but does not mention anything about the value ofdeadline
in that case.Should it? Or is it self-evident on the basis that things which return
(T, bool)
generally return the zero value forT
when the boolean is false?I do realize that
context.Context
is an interface, but it would be nice to be able to rely ondeadline == time.Time{}
when the context has no associated deadline.I propose changing the documentation to
Deadline returns deadline == time.Time{} and ok == false when no deadline is set
for clarification. If this is acceptable, I can send a CL.The text was updated successfully, but these errors were encountered: