Commit dc4427f3 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

context: make DeadlineExceeded have a Timeout method

Fixes #14238

Change-Id: I1538bfb5cfa63e36a89df1f6eb9f5a0dcafb6ce5
Reviewed-on: https://go-review.googlesource.com/23256Reviewed-by: default avatarDave Cheney <dave@cheney.net>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 0b806598
......@@ -144,7 +144,13 @@ var Canceled = errors.New("context canceled")
// DeadlineExceeded is the error returned by Context.Err when the context's
// deadline passes.
var DeadlineExceeded = errors.New("context deadline exceeded")
var DeadlineExceeded error = deadlineExceededError{}
type deadlineExceededError struct{}
func (deadlineExceededError) Error() string { return "context deadline exceeded" }
func (deadlineExceededError) Timeout() bool { return true }
// An emptyCtx is never canceled, has no values, and has no deadline. It is not
// struct{}, since vars of this type must have distinct addresses.
......
......@@ -594,3 +594,15 @@ func recoveredValue(fn func()) (v interface{}) {
fn()
return
}
func TestDeadlineExceededSupportsTimeout(t *testing.T) {
i, ok := DeadlineExceeded.(interface {
Timeout() bool
})
if !ok {
t.Fatal("DeadlineExceeded does not support Timeout interface")
}
if !i.Timeout() {
t.Fatal("wrong value for timeout")
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment