github.com/weaveworks/common@v0.0.0-20230728070032-dd9e68f319d5/grpc/cancel.go (about) 1 package grpc 2 3 import ( 4 "context" 5 "errors" 6 7 "google.golang.org/grpc/codes" 8 "google.golang.org/grpc/status" 9 ) 10 11 // IsCanceled checks whether an error comes from an operation being canceled 12 func IsCanceled(err error) bool { 13 if errors.Is(err, context.Canceled) { 14 return true 15 } 16 s, ok := status.FromError(err) 17 if ok && s.Code() == codes.Canceled { 18 return true 19 } 20 return false 21 }