github.com/blend/go-sdk@v1.20220411.3/grpcutil/unary_client_timeout.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package grpcutil 9 10 import ( 11 "context" 12 "time" 13 14 "google.golang.org/grpc" 15 ) 16 17 // UnaryClientTimeout returns a unary client interceptor. 18 func UnaryClientTimeout(timeout time.Duration) grpc.UnaryClientInterceptor { 19 return func(ctx context.Context, method string, req interface{}, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { 20 timeoutCtx, done := context.WithTimeout(ctx, timeout) 21 defer done() 22 return invoker(timeoutCtx, method, req, reply, cc, opts...) 23 } 24 }