galenwarren commented on pull request #303:
URL: https://github.com/apache/flink-statefun/pull/303#issuecomment-1050095203


   > Can you please explain to me how this works?
   
   I think it's just the [behavior](https://pkg.go.dev/context#WithValue) of 
`context.WithValue`, i.e. 
   
   > WithValue returns a copy of parent in which the value associated with key 
is val.
   
   So the new context is a copy of the original -- all the kv pairs, the Done 
channel, etc., but just with the new kv pair added. So these extended contexts 
form a tree structure, i.e. each child context uses its parent as the starting 
point.
   
   > Why isn't derive just a variable reassignment as it looks in the code?
   
   In an `Invoke` method, we just have access to the interface 
`statefun.Context`, but an assignment of Context would have to happen on the 
non-exported type `statefunContext` that implements that interface.  
   
   The reason to replace the context completely -- as opposed to, say, allowing 
one to assign kv pairs in `statefun.Context`  -- is that, often, the context 
keys are non-exported types, and the only way to put a new value into context 
is via an exported function that returns a `context.Context`. An example would 
be the `WithLogger` function, 
[here](https://pkg.go.dev/knative.dev/pkg/logging#WithLogger).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to