File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -66,28 +66,29 @@ type Env struct {
6666// context, it returns the context of its parent, or if e has no parent it
6767// returns a new background context.
6868func (e * Env ) Context () context.Context {
69- if e . ctx != nil {
70- return e .ctx
71- } else if e . Parent == nil {
72- return context . Background ()
69+ for cur := e ; cur != nil ; cur = cur . Parent {
70+ if cur .ctx != nil {
71+ return cur . ctx
72+ }
7373 }
74- return e . Parent . Context ()
74+ return context . Background ()
7575}
7676
7777// Cancel cancels the context associated with e with the given cause.
7878// If e does not have its own context, the cancellation is propagated to its
7979// parent if one exists. If e has no parent and no context, Cancel does nothing
8080// without error.
8181func (e * Env ) Cancel (cause error ) {
82- if e .cancel != nil {
83- e .cancel (cause )
84- } else if e .Parent != nil {
85- e .Parent .Cancel (cause )
82+ for cur := e ; cur != nil ; cur = cur .Parent {
83+ if cur .cancel != nil {
84+ cur .cancel (cause )
85+ return
86+ }
8687 }
8788}
8889
8990// SetContext sets the context of e to ctx and returns e. If ctx == nil it
90- // clears the context of e so that it defaults to its parent (see Context).
91+ // clears the context of e so that it defaults to its parent (see [Env. Context] ).
9192func (e * Env ) SetContext (ctx context.Context ) * Env {
9293 if ctx == nil {
9394 e .ctx = nil
You can’t perform that action at this time.
0 commit comments