timeout

package
v2.0.0-rc.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2022 License: Apache-2.0 Imports: 3 Imported by: 19

Documentation

Overview

Package timeout is a middleware that responds with a timeout error after the given duration.

`grpc_timeout` are interceptors that timeout for gRPC client calls.

Client Side Timeout Middleware

Please see examples for simple examples of use.

Example (Initialization)

Initialization shows an initialization sequence with a custom client request timeout.

package main

import (
	"context"
	"log"
	"time"

	"google.golang.org/grpc"

	"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/timeout"
	"github.com/grpc-ecosystem/go-grpc-middleware/v2/testing/testpb"
)

func main() {
	clientConn, err := grpc.Dial(
		"ServerAddr",
		grpc.WithUnaryInterceptor(
			// Set your client request timeout.
			timeout.TimeoutUnaryClientInterceptor(20*time.Millisecond),
		),
	)
	if err != nil {
		log.Fatal(err)
	}

	// Initialize your grpc service with connection.
	testServiceClient := testpb.NewTestServiceClient(clientConn)
	resp, err := testServiceClient.Ping(context.TODO(), &testpb.PingRequest{Value: "my_example_value"})
	if err != nil {
		log.Fatal(err)
	}

	// Use grpc response value.
	log.Println(resp.Value)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func TimeoutUnaryClientInterceptor

func TimeoutUnaryClientInterceptor(timeout time.Duration) grpc.UnaryClientInterceptor

TimeoutUnaryClientInterceptor returns a new unary client interceptor that sets a timeout on the request context.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL