Skip to content

Commit 2058c2c

Browse files
committed
added IsContextError
1 parent be0e13b commit 2058c2c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

context.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,10 @@ func IsContextDone(ctx context.Context) bool {
3636
return false
3737
}
3838
}
39+
40+
// IsContextError returns true if err unwraps to
41+
// context.Canceled or context.DeadlineExceeded.
42+
func IsContextError(err error) bool {
43+
return err != nil &&
44+
(errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded))
45+
}

0 commit comments

Comments
 (0)