File tree 3 files changed +59
-5
lines changed
3 files changed +59
-5
lines changed Original file line number Diff line number Diff line change @@ -13,8 +13,7 @@ const abortIndex int8 = math.MaxInt8 >> 1
13
13
type Context struct {
14
14
engine * Engine
15
15
16
- Event * event.Event
17
- ctx context.Context
16
+ Request * Request
18
17
19
18
handlers HandlersChain
20
19
index int8
@@ -88,5 +87,5 @@ func (c *Context) Error(err error) *Error {
88
87
}
89
88
90
89
func (c * Context ) Done () <- chan struct {} {
91
- return c .ctx .Done ()
90
+ return c .Request . Context () .Done ()
92
91
}
Original file line number Diff line number Diff line change @@ -297,16 +297,20 @@ func (w *worker) run() {
297
297
c := w .engine .pool .Get ().(* Context )
298
298
c .reset ()
299
299
300
+ var ctx context.Context
301
+ ctx , w .cancelCtx = context .WithCancel (context .Background ())
302
+
300
303
var err error
301
- c . Event , err = binding .ToEvent (context .Background (), w .message )
304
+ e , err : = binding .ToEvent (context .Background (), w .message )
302
305
if err != nil {
303
306
_ , filename , line , _ := runtime .Caller (0 )
304
307
c .Error (err ).SetType (ErrorTypeBind ).SetMeta (H {
305
308
"filename" : filename ,
306
309
"line" : line + 1 })
307
310
}
311
+ c .Request = & Request {Event : e , ctx : ctx }
312
+
308
313
c .handlers = w .subscription .handlers
309
- c .ctx , w .cancelCtx = context .WithCancel (context .Background ())
310
314
c .Next ()
311
315
312
316
if c .IsNack () {
Original file line number Diff line number Diff line change
1
+ package equeue
2
+
3
+ import (
4
+ "context"
5
+
6
+ "github.com/cloudevents/sdk-go/v2/event"
7
+ )
8
+
9
+ // http.Request
10
+ type Request struct {
11
+ Event * event.Event
12
+
13
+ ctx context.Context
14
+ }
15
+
16
+ // Context returns the request's context. To change the context, use
17
+ // Clone or WithContext.
18
+ //
19
+ // The returned context is always non-nil; it defaults to the
20
+ // background context.
21
+ //
22
+ // For outgoing client requests, the context controls cancellation.
23
+ //
24
+ // For incoming server requests, the context is canceled when the
25
+ // client's connection closes, the request is canceled (with HTTP/2),
26
+ // or when the ServeHTTP method returns.
27
+ func (r * Request ) Context () context.Context {
28
+ if r .ctx != nil {
29
+ return r .ctx
30
+ }
31
+ return context .Background ()
32
+ }
33
+
34
+ // WithContext returns a shallow copy of r with its context changed
35
+ // to ctx. The provided ctx must be non-nil.
36
+ //
37
+ // For outgoing client request, the context controls the entire
38
+ // lifetime of a request and its response: obtaining a connection,
39
+ // sending the request, and reading the response headers and body.
40
+ //
41
+ // To create a new request with a context, use NewRequestWithContext.
42
+ // To make a deep copy of a request with a new context, use Request.Clone.
43
+ func (r * Request ) WithContext (ctx context.Context ) * Request {
44
+ if ctx == nil {
45
+ panic ("nil context" )
46
+ }
47
+ r2 := new (Request )
48
+ * r2 = * r
49
+ r2 .ctx = ctx
50
+ return r2
51
+ }
You can’t perform that action at this time.
0 commit comments