|
|
@ -11,9 +11,10 @@ import (
|
|
|
|
func TimeoutInterceptor(timeout time.Duration) grpc.UnaryClientInterceptor {
|
|
|
|
func TimeoutInterceptor(timeout time.Duration) grpc.UnaryClientInterceptor {
|
|
|
|
return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn,
|
|
|
|
return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn,
|
|
|
|
invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
|
|
|
|
invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
|
|
|
|
if timeout == 0 {
|
|
|
|
if timeout <= 0 {
|
|
|
|
return invoker(ctx, method, req, reply, cc, opts...)
|
|
|
|
return invoker(ctx, method, req, reply, cc, opts...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ctx, cancel := contextx.ShrinkDeadline(ctx, timeout)
|
|
|
|
ctx, cancel := contextx.ShrinkDeadline(ctx, timeout)
|
|
|
|
defer cancel()
|
|
|
|
defer cancel()
|
|
|
|
return invoker(ctx, method, req, reply, cc, opts...)
|
|
|
|
return invoker(ctx, method, req, reply, cc, opts...)
|
|
|
|