Skip to content

Commit

Permalink
remove all old imports of "golang.org/x/net/context"; replace with "c…
Browse files Browse the repository at this point in the history
…ontext" (#495)
  • Loading branch information
jhump committed Feb 13, 2022
1 parent 3240deb commit 0c2aedc
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 7 deletions.
14 changes: 13 additions & 1 deletion dynamic/grpcdynamic/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
package grpcdynamic

import (
"context"
"fmt"
"io"

"github.com/golang/protobuf/proto"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"

Expand Down Expand Up @@ -74,6 +74,7 @@ func (s Stub) InvokeRpcServerStream(ctx context.Context, method *desc.MethodDesc
ClientStreams: method.IsClientStreaming(),
}
if cs, err := s.channel.NewStream(ctx, &sd, requestMethod(method), opts...); err != nil {
cancel()
return nil, err
} else {
err = cs.SendMsg(request)
Expand All @@ -86,6 +87,11 @@ func (s Stub) InvokeRpcServerStream(ctx context.Context, method *desc.MethodDesc
cancel()
return nil, err
}
go func() {
// when the new stream is finished, also cleanup the parent context
<-cs.Context().Done()
cancel()
}()
return &ServerStream{cs, method.GetOutputType(), s.mf}, nil
}
}
Expand All @@ -103,8 +109,14 @@ func (s Stub) InvokeRpcClientStream(ctx context.Context, method *desc.MethodDesc
ClientStreams: method.IsClientStreaming(),
}
if cs, err := s.channel.NewStream(ctx, &sd, requestMethod(method), opts...); err != nil {
cancel()
return nil, err
} else {
go func() {
// when the new stream is finished, also cleanup the parent context
<-cs.Context().Done()
cancel()
}()
return &ClientStream{cs, method, s.mf, cancel}, nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion dynamic/grpcdynamic/stub_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package grpcdynamic

import (
"context"
"fmt"
"io"
"net"
"os"
"testing"

"github.com/golang/protobuf/proto"
"golang.org/x/net/context"
"google.golang.org/grpc"

"github.com/jhump/protoreflect/desc"
Expand Down
2 changes: 1 addition & 1 deletion dynamic/msgregistry/fetchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package msgregistry

import (
"bytes"
"context"
"errors"
"fmt"
"io/ioutil"
Expand All @@ -13,7 +14,6 @@ import (
"time"

"github.com/golang/protobuf/proto"
"golang.org/x/net/context"
"google.golang.org/genproto/protobuf/ptype"
"google.golang.org/genproto/protobuf/source_context"

Expand Down
2 changes: 1 addition & 1 deletion dynamic/msgregistry/ptype_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package msgregistry

import (
"bytes"
"context"
"fmt"
"reflect"
"sort"
Expand All @@ -12,7 +13,6 @@ import (
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/protoc-gen-go/descriptor"
"github.com/golang/protobuf/ptypes/wrappers"
"golang.org/x/net/context"
"google.golang.org/genproto/protobuf/api"
"google.golang.org/genproto/protobuf/ptype"

Expand Down
2 changes: 1 addition & 1 deletion grpcreflect/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package grpcreflect

import (
"bytes"
"context"
"fmt"
"io"
"reflect"
Expand All @@ -10,7 +11,6 @@ import (

"github.com/golang/protobuf/proto"
dpb "github.com/golang/protobuf/protoc-gen-go/descriptor"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
rpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
"google.golang.org/grpc/status"
Expand Down
2 changes: 1 addition & 1 deletion grpcreflect/client_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package grpcreflect

import (
"context"
"encoding/base64"
"fmt"
"io"
Expand All @@ -13,7 +14,6 @@ import (

_ "github.com/golang/protobuf/protoc-gen-go/plugin"
_ "github.com/golang/protobuf/ptypes/empty"
"golang.org/x/net/context"
_ "google.golang.org/genproto/protobuf/api"
_ "google.golang.org/genproto/protobuf/field_mask"
_ "google.golang.org/genproto/protobuf/ptype"
Expand Down
2 changes: 1 addition & 1 deletion internal/testutil/testservice.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package testutil

import (
"context"
"io"

grpc_testing "github.com/jhump/protoreflect/internal/testprotos/grpc"
"golang.org/x/net/context"
)

// TestService is a very simple test service that just echos back request payloads
Expand Down

0 comments on commit 0c2aedc

Please sign in to comment.