modify server side Serve methods to no longer generate a cancel
context, and defer in it's calling.
This is done so that there can be asynchronous calls that spawn off
of the Server side that can inherit from the given context.Context.
Theodore Schnepper
7 years ago
73 | 73 |
|
74 | 74 |
// ServeGRPC implements the Handler interface.
|
75 | 75 |
func (s Server) ServeGRPC(grpcCtx context.Context, req interface{}) (context.Context, interface{}, error) {
|
76 | |
ctx, cancel := context.WithCancel(s.ctx)
|
77 | |
defer cancel()
|
|
76 |
ctx := s.ctx
|
78 | 77 |
|
79 | 78 |
// Retrieve gRPC metadata.
|
80 | 79 |
md, ok := metadata.FromContext(grpcCtx)
|
75 | 75 |
|
76 | 76 |
// ServeHTTP implements http.Handler.
|
77 | 77 |
func (s Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
78 | |
ctx, cancel := context.WithCancel(s.ctx)
|
79 | |
defer cancel()
|
|
78 |
ctx := s.ctx
|
80 | 79 |
|
81 | 80 |
for _, f := range s.before {
|
82 | 81 |
ctx = f(ctx, r)
|
50 | 50 |
|
51 | 51 |
// ServeHTTP implements http.Handler.
|
52 | 52 |
func (s Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
53 | |
ctx, cancel := context.WithCancel(s.ctx)
|
54 | |
defer cancel()
|
|
53 |
ctx := s.ctx
|
55 | 54 |
|
56 | 55 |
for _, f := range s.before {
|
57 | 56 |
ctx = f(ctx, r)
|